Created
October 9, 2012 00:49
-
-
Save masayang/3855895 to your computer and use it in GitHub Desktop.
簡単なLinear Regression例
This file contains hidden or 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
import numpy as np | |
from sklearn import linear_model | |
import matplotlib.pyplot as plt | |
X = np.array([[0], [1], [2], [3]]) | |
Y = np.array([0.1, 1.1, 1.8, 2.7]) | |
regr = linear_model.LinearRegression() | |
regr.fit(X, Y) | |
print 'Coefficients: %f' % regr.coef_ | |
print 'Residual sum of squares: %f' % np.mean((regr.predict(X) - Y) ** 2) | |
print 'Variance score %f' % regr.score(X, Y) | |
plt.scatter(X, Y) | |
plt.plot(X, regr.predict(X), color = 'blue', linewidth = 3) | |
plt.savefig("simple.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment