Skip to content

Instantly share code, notes, and snippets.

Created November 18, 2020 11:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Scikit-learn LinearRegression vs Numpy Polyfit
def regression_line(model, coefs, intercept, X_):
print('Coefficients: {}'.format(coefs))
print('Intercept: {}'.format(intercept))
print('Error: {}'.format(np.linalg.norm(y - model.predict(X_)) ** 2))
plt.scatter(x, y, label="observed")
plt.plot(x, model.predict(X_), c='red', label="fitted")
regression_line(linear_reg_1d, linear_reg_1d.coef_[1:], linear_reg_1d.intercept_, X1)
regression_line(linear_reg_2d, linear_reg_2d.coef_[1:], linear_reg_2d.intercept_, X2)
regression_line(linear_reg_3d, linear_reg_3d.coef_[1:], linear_reg_3d.intercept_, X3)
regression_line(linear_reg_4d, linear_reg_4d.coef_[1:], linear_reg_4d.intercept_, X4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment