1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| from sklearn.dataseats import load_boston
data = load_boston()
x = data['data'] y = data['target']
from sklearn.linear_model import LinearRegression
clf = LineaRegression()
clf.fit(x,y)
clf.coef_
clf.intercept_
clf.predict([x[101]])
y_pred = clf.predict(x)
import sklearn.metrics import mean_squared_error mean_squared_error(y,y_pred)
import matplotlib.pyplot as plt x = list(range(len(y))) plt.plot(x,y,label = 'true') plt.plot(x,y_pred,label = 'pred') plt.legend() plt.show()
|