In [1]:
from sklearn import datasets
from sklearn.cross_validation import cross_val_predict
from sklearn import linear_model
import matplotlib.pyplot as plt
In [2]:
lr = linear_model.LinearRegression()
boston = datasets.load_boston()
y = boston.target
# boston.data[506]*13
In [3]:
# cross_val_predict returns an array of the same size as `y` where each entry
# is a prediction obtained by cross validated:
# cv:A cross-validation generator to use. If int, determines the number of folds in StratifiedKFold.
predicted = cross_val_predict(lr, boston.data, y, cv=10)
In [9]:
fig,ax = plt.subplots()
In [10]:
ax.scatter(y, predicted)
ax.plot([y.min(), y.max()], [y.min(), y.max()], 'r--', lw=4)
ax.set_xlabel('Measured')
ax.set_ylabel('Predicted')
fig.show()
In [11]:
plt.show()