Advertisement
Guest User

plot_cv_predict.py

a guest
May 23rd, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. """
  2. ====================================
  3. Plotting Cross-Validated Predictions
  4. ====================================
  5.  
  6. This example shows how to use `cross_val_predict` to visualize prediction
  7. errors.
  8.  
  9. """
  10. from sklearn import datasets
  11. from sklearn.model_selection import cross_val_predict
  12. from sklearn import linear_model
  13. import matplotlib.pyplot as plt
  14.  
  15. lr = linear_model.LinearRegression()
  16. boston = datasets.load_boston()
  17. y = boston.target
  18.  
  19. # cross_val_predict returns an array of the same size as `y` where each entry
  20. # is a prediction obtained by cross validation:
  21. predicted = cross_val_predict(lr, boston.data, y, cv=10)
  22.  
  23. fig, ax = plt.subplots()
  24. ax.scatter(y, predicted, edgecolors=(0, 0, 0))
  25. ax.plot([y.min(), y.max()], [y.min(), y.max()], 'k--', lw=4)
  26. ax.set_xlabel('Measured')
  27. ax.set_ylabel('Predicted')
  28. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement