Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Manikant92/6e3c4d90a78766fd7522617891aabce4 to your computer and use it in GitHub Desktop.
Save Manikant92/6e3c4d90a78766fd7522617891aabce4 to your computer and use it in GitHub Desktop.
#convert into numpy arrays as scikit learn works on top of numpy array
new_x = np.array(new_x)
new_y = np.array(new_y)
#reshape x as we cannot use Rank 1 matrix in scikit learn
new_x = new_x.reshape(len(new_x),1)
#fit to determine slope and intercept by passing all input and output data
lr.fit(new_x,new_y)
print('Slope with Linear Regression SciKit Learn: ', lr.coef_[0])
print('Intercept with Linear Regression SciKit Learn: ',lr.intercept_)
#output:
Slope with Linear Regression SciKit Learn: 2.35757575758
Intercept with Linear Regression SciKit Learn: 7.37575757576
#output is same as which we have implemented from scratch.
#cause Scikit linear regression algorithm is built using same OLS method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment