Visualization of the prediction error of a regression model.
This tool can display “residuals vs predicted” or “actual vs predicted” using scatter plots to qualitatively assess the behavior of a regressor, preferably on held-out data points.
See the details in the docstrings of from_estimator or from_predictions to create a visualizer. All parameters are stored as attributes.
For general information regarding scikit-learn visualization tools, read more in the Visualization Guide. For details regarding interpreting these plots, refer to the Model Evaluation Guide.
Added in version 1.2.
True values.
Prediction values.
Optimal line representing y_true == y_pred. Therefore, it is a diagonal line for kind="predictions" and a horizontal line for kind="residuals".
Residual lines. If with_errors=False, then it is set to None.
Scatter data points.
Axes with the different matplotlib axis.
Figure containing the scatter and lines.
See also
PredictionErrorDisplay.from_estimatorPrediction error visualization given an estimator and some data.
PredictionErrorDisplay.from_predictionsPrediction error visualization given the true and predicted targets.
>>> import matplotlib.pyplot as plt >>> from sklearn.datasets import load_diabetes >>> from sklearn.linear_model import Ridge >>> from sklearn.metrics import PredictionErrorDisplay >>> X, y = load_diabetes(return_X_y=True) >>> ridge = Ridge().fit(X, y) >>> y_pred = ridge.predict(X) >>> display = PredictionErrorDisplay(y_true=y, y_pred=y_pred) >>> display.plot() <...> >>> plt.show()
Plot the prediction error given a regressor and some data.
For general information regarding scikit-learn visualization tools, read more in the Visualization Guide. For details regarding interpreting these plots, refer to the Model Evaluation Guide.
Added in version 1.2.
Fitted regressor or a fitted Pipeline in which the last estimator is a regressor.
Input values.
Target values.
The type of plot to draw:
Sampling the samples to be shown on the scatter plot. If float, it should be between 0 and 1 and represents the proportion of the original dataset. If int, it represents the number of samples display on the scatter plot. If None, no subsampling will be applied. by default, 1000 samples or less will be displayed.
Controls the randomness when subsample is not None. See Glossary for details.
Axes object to plot on. If None, a new figure and axes is created.
Dictionary with keywords passed to the matplotlib.pyplot.scatter call.
Dictionary with keyword passed to the matplotlib.pyplot.plot call to draw the optimal line.
PredictionErrorDisplay
Object that stores the computed values.
See also
PredictionErrorDisplayPrediction error visualization for regression.
PredictionErrorDisplay.from_predictionsPrediction error visualization given the true and predicted targets.
>>> import matplotlib.pyplot as plt >>> from sklearn.datasets import load_diabetes >>> from sklearn.linear_model import Ridge >>> from sklearn.metrics import PredictionErrorDisplay >>> X, y = load_diabetes(return_X_y=True) >>> ridge = Ridge().fit(X, y) >>> disp = PredictionErrorDisplay.from_estimator(ridge, X, y) >>> plt.show()
Plot the prediction error given the true and predicted targets.
For general information regarding scikit-learn visualization tools, read more in the Visualization Guide. For details regarding interpreting these plots, refer to the Model Evaluation Guide.
Added in version 1.2.
True target values.
Predicted target values.
The type of plot to draw:
Sampling the samples to be shown on the scatter plot. If float, it should be between 0 and 1 and represents the proportion of the original dataset. If int, it represents the number of samples display on the scatter plot. If None, no subsampling will be applied. by default, 1000 samples or less will be displayed.
Controls the randomness when subsample is not None. See Glossary for details.
Axes object to plot on. If None, a new figure and axes is created.
Dictionary with keywords passed to the matplotlib.pyplot.scatter call.
Dictionary with keyword passed to the matplotlib.pyplot.plot call to draw the optimal line.
PredictionErrorDisplay
Object that stores the computed values.
See also
PredictionErrorDisplayPrediction error visualization for regression.
PredictionErrorDisplay.from_estimatorPrediction error visualization given an estimator and some data.
>>> import matplotlib.pyplot as plt >>> from sklearn.datasets import load_diabetes >>> from sklearn.linear_model import Ridge >>> from sklearn.metrics import PredictionErrorDisplay >>> X, y = load_diabetes(return_X_y=True) >>> ridge = Ridge().fit(X, y) >>> y_pred = ridge.predict(X) >>> disp = PredictionErrorDisplay.from_predictions(y_true=y, y_pred=y_pred) >>> plt.show()
Plot visualization.
Extra keyword arguments will be passed to matplotlib’s plot.
Axes object to plot on. If None, a new figure and axes is created.
The type of plot to draw:
Dictionary with keywords passed to the matplotlib.pyplot.scatter call.
Dictionary with keyword passed to the matplotlib.pyplot.plot call to draw the optimal line.
PredictionErrorDisplay
Object that stores computed values.
© 2007–2025 The scikit-learn developers
Licensed under the 3-clause BSD License.
https://scikit-learn.org/1.6/modules/generated/sklearn.metrics.PredictionErrorDisplay.html