Simple Linear Regression - Assign3
Simple Linear Regression - Assign3
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 organization wanted an early estimate of their employee churn out rate. So, the HR
department came up with data regarding the employee’s salary hike and churn out rate for a
financial year. The analytics team will have to perform a deep analysis and predict an estimate
of employee churn and present the statistics. Approach –A Simple Linear regression model
needs to be built with target variable ‘Churn_out_rate’. 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 .
Exploratory data analysis is performed on data
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()
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.