scikit-learn/examples/model_selection/plot_cv_predict.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

30 lines
840 B
Python
Raw Normal View History

"""
====================================
Plotting Cross-Validated Predictions
====================================
This example shows how to use
:func:`~sklearn.model_selection.cross_val_predict` to visualize prediction
errors.
"""
from sklearn import datasets
from sklearn.model_selection import cross_val_predict
from sklearn import linear_model
import matplotlib.pyplot as plt
lr = linear_model.LinearRegression()
X, y = datasets.load_diabetes(return_X_y=True)
# cross_val_predict returns an array of the same size as `y` where each entry
2016-05-17 20:24:25 +08:00
# is a prediction obtained by cross validation:
predicted = cross_val_predict(lr, X, y, cv=10)
2015-07-28 14:34:09 +08:00
fig, ax = plt.subplots()
ax.scatter(y, predicted, edgecolors=(0, 0, 0))
ax.plot([y.min(), y.max()], [y.min(), y.max()], "k--", lw=4)
ax.set_xlabel("Measured")
ax.set_ylabel("Predicted")
2015-07-28 14:34:09 +08:00
plt.show()