Simple Linear Regression - Assignn5
Simple Linear Regression - Assignn5
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 student from a certain University was asked to prepare a dataset and build a
prediction model for predicting SAT scores based on the exam giver’s GPA. Approach
- A regression model needs to be built with target variable ‘SAT_Scores’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, 𝑦).
SAT_GPA.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(gpa),y=score
Exponential transformation
#x=(gpa),y=log(score)
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.