Simple Linear Regression - Assign
Simple Linear Regression - Assign
There are five basic steps when you’re implementing linear regression:
These steps are more or less general for most of the regression approaches and implementations.
Problem Statement: -
A certain food based company conducted a survey with the help of a fitness company spread
across the country to find relationship between a person’s weight gain and the no of calories
consumed by them in order to come up a diet plan for individuals that fall under different
weight groups. Approach - A Simple Linear regression model needs to be built with target
variable ‘Calories.Consumed’. Apply necessary transformations and record the RMSE values,
Correlation coefficient values for different transformation models.
import numpy as np
from sklearn.linear_model import LinearRegression
Now, you have all the functionalities you need to implement linear regression.
The fundamental data type of NumPy is the array type called numpy.ndarray. The rest of this article
uses the term array to refer to instances of the type numpy.ndarray.
The second step is defining data to work with. The inputs (regressors, 𝑥) and output (predictor, 𝑦).
calories_consumed.csv is imported .
The next step is to create a linear regression model and fit it using the existing data.
Let’s create an instance of the class LinearRegression, which will represent the regression model:
model1=smf.ols('calories ~ weight',data=cal_data).fit()
In order to reduce the errors and to obtain best fit line Transformation is performed on data
Log transformation
#x=log(weight),y=calories
Exponential transformation
#x=(weight),y=log(calories)
choose the best model by using all RMSE values of above transformations
Once you have your model fitted, you can get the results to check whether the model works
satisfactorily and interpret it.