Is the prediction of how two variables are related to each other, in Python you need a data frame to start working on linear regression, eighther it is already there, or you need to create your own data frame using Pandas
, assuming data frame is ready and contains the required parameters; do the following steps to have a linear regression model:
LinearRegression
from sk.linear_model
lm.fit()
-> fits a linear modellm.predict()
-> Predict Y using the linear model with estimated coefficientslm.score()
-> Returns the coefficient of determination (R^2).coef_
gives the coefficients.intercept_
gives the estimated intercepts.lm.fit()
, the first argument is the x-axis data, the second is the y-axis dataLinearRegression(copy_X=True, fit_intercept=True, normalize=False)
plot
to plot that feature against the y-axis of step 4Example plot:
Resources: bigdata-madesimple