Created
November 18, 2020 11:09
-
-
Save yuyasugano/f92d391138bb1375e9e37cf0c612886e to your computer and use it in GitHub Desktop.
Scikit-learn LinearRegression vs Numpy Polyfit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
plt.grid() | |
plt.legend() | |
plt.show() | |
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