Simple Linear Regression - Assign2
Simple Linear Regression - Assign2
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 food delivery service recorded the data of delivery time taken and the time taken for the
deliveries to be sorted by the restaurants in order to improve their delivery services.
Approach – A Simple Linear regression model needs to be built with target variable
‘Delivery.Time’. 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(sort_time),y=time
Exponential transformation
#x=(sort_time),y=log(time)
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.