PredictionErrorDisplay#
- class skore.PredictionErrorDisplay(*, y_true, y_pred, estimator_name, data_source=None)[source]#
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.
An instance of this class is should created by
EstimatorReport.metrics.prediction_error()
. You should not create an instance of this class directly.- Parameters:
- y_truelist of ndarray of shape (n_samples,)
True values.
- y_predlist of ndarray of shape (n_samples,)
Prediction values.
- estimator_namestr
Name of the estimator.
- data_source{“train”, “test”, “X_y”}, default=None
The data source used to display the prediction error.
- Attributes:
- line_matplotlib Artist
Optimal line representing
y_true == y_pred
. Therefore, it is a diagonal line forkind="predictions"
and a horizontal line forkind="residuals"
.- errors_lines_matplotlib Artist or None
Residual lines. If
with_errors=False
, then it is set toNone
.- scatter_matplotlib Artist
Scatter data points.
- ax_matplotlib Axes
Axes with the different matplotlib axis.
- figure_matplotlib Figure
Figure containing the scatter and lines.
Examples
>>> from sklearn.datasets import load_diabetes >>> from sklearn.linear_model import Ridge >>> from sklearn.model_selection import train_test_split >>> from skore import EstimatorReport >>> X_train, X_test, y_train, y_test = train_test_split( ... *load_diabetes(return_X_y=True), random_state=0 ... ) >>> classifier = Ridge() >>> report = EstimatorReport( ... classifier, ... X_train=X_train, ... y_train=y_train, ... X_test=X_test, ... y_test=y_test, ... ) >>> display = report.metrics.prediction_error() >>> display.plot(kind="actual_vs_predicted")
- plot(ax=None, *, estimator_name=None, kind='residual_vs_predicted', scatter_kwargs=None, line_kwargs=None, despine=True)[source]#
Plot visualization.
Extra keyword arguments will be passed to matplotlib’s
plot
.- Parameters:
- axmatplotlib axes, default=None
Axes object to plot on. If
None
, a new figure and axes is created.- estimator_namestr
Name of the estimator used to plot the prediction error. If
None
, we used the inferred name from the estimator.- kind{“actual_vs_predicted”, “residual_vs_predicted”}, default=”residual_vs_predicted”
The type of plot to draw:
“actual_vs_predicted” draws the observed values (y-axis) vs. the predicted values (x-axis).
“residual_vs_predicted” draws the residuals, i.e. difference between observed and predicted values, (y-axis) vs. the predicted values (x-axis).
- scatter_kwargsdict, default=None
Dictionary with keywords passed to the
matplotlib.pyplot.scatter
call.- line_kwargsdict, default=None
Dictionary with keyword passed to the
matplotlib.pyplot.plot
call to draw the optimal line.- despinebool, default=True
Whether to remove the top and right spines from the plot.
Examples
>>> from sklearn.datasets import load_diabetes >>> from sklearn.linear_model import Ridge >>> from sklearn.model_selection import train_test_split >>> from skore import EstimatorReport >>> X_train, X_test, y_train, y_test = train_test_split( ... *load_diabetes(return_X_y=True), random_state=0 ... ) >>> classifier = Ridge() >>> report = EstimatorReport( ... classifier, ... X_train=X_train, ... y_train=y_train, ... X_test=X_test, ... y_test=y_test, ... ) >>> display = report.metrics.prediction_error() >>> display.plot(kind="actual_vs_predicted")