Simple Linear Regression - Assign4
Simple Linear Regression - Assign4
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: -
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.
Salary_data.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)
Polynomial transformation
choose the best model by using all RMSE values of above transformations
final model is fitted on train and test split data and prediction is observed