PredictionErrorDisplay#

class skore.PredictionErrorDisplay(*, prediction_error, range_y_true, range_y_pred, range_residuals, data_source, ml_task, report_type)[source]#

Plot the prediction error of a regression model.

Parameters:
prediction_errorDataFrame

The prediction error data to display. The columns are

  • estimator

  • data_source

  • split (may be null)

  • output

  • y_true

  • y_pred

  • residuals.

range_y_trueRangeData

Global range of the true values.

range_y_predRangeData

Global range of the predicted values.

range_residualsRangeData

Global range of the residuals.

data_source{“train”, “test”, “both”}

The data source used to display the prediction error.

ml_task{“regression”, “multioutput-regression”}

The machine learning task.

report_type{“comparison-cross-validation”, “comparison-estimator”, “cross-validation”, “estimator”}

The type of report.

Attributes:
range_y_trueRangeData

Global range of the true target values.

range_y_predRangeData

Global range of the predicted values.

range_residualsRangeData

Global range of the residuals.

data_sourceDataSource or “both”

The data source used for the display.

ml_taskMLTask

The machine learning task.

report_typeReportType

The type of report.

See also

EstimatorReport.metrics.prediction_error

Create this display from a report.

MetricsSummaryDisplay

Summarize scalar regression metrics.

Examples

>>> from sklearn.datasets import load_diabetes
>>> from sklearn.linear_model import Ridge
>>> from skore import evaluate
>>> X, y = load_diabetes(return_X_y=True)
>>> classifier = Ridge()
>>> report = evaluate(classifier, X, y, splitter=0.2)
>>> display = report.metrics.prediction_error()
>>> display.plot(kind="actual_vs_predicted")
frame()[source]#

Get the data used to create the prediction error plot.

Returns:
DataFrame

A DataFrame containing the prediction error data with columns depending on the report type:

  • estimator: Name of the estimator (when comparing estimators)

  • split: Cross-validation split ID (when doing cross-validation)

  • data_source : train or test set (when displaying both data sources)

  • output: Index of the output target (for multioutput-regression)

  • y_true: True target values

  • y_pred: Predicted target values

  • residuals: Difference between true and predicted values (y_true - y_pred)

Examples

>>> from sklearn.datasets import load_diabetes
>>> from sklearn.linear_model import Ridge
>>> from skore import evaluate
>>> X, y = load_diabetes(return_X_y=True)
>>> reg = Ridge()
>>> report = evaluate(reg, X, y, splitter=0.2)
>>> display = report.metrics.prediction_error()
>>> df = display.frame()
help()[source]#

Display display help using rich or HTML.

plot(*, subplot_by='auto', kind='residual_vs_predicted', despine=True)[source]#

Plot the prediction error.

Parameters:
subplot_by{“auto”, “data_source”, “split”, “estimator”, “output”} or None, default=”auto”

The variable to use for creating subplots:

  • “auto” creates subplots by estimator for comparison reports, otherwise uses a single plot.

  • “data_source” creates subplots by data source (train/test).

  • “split” creates subplots by cross-validation split.

  • “estimator” creates subplots by estimator.

  • “output” creates subplots by output target.

  • None creates a single plot.

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).

despinebool, default=True

Whether to remove the top and right spines from the plot.

Returns:
matplotlib.figure.Figure

Figure containing the prediction error plot.

Examples

>>> from sklearn.datasets import load_diabetes
>>> from sklearn.linear_model import Ridge
>>> from skore import evaluate
>>> X, y = load_diabetes(return_X_y=True)
>>> classifier = Ridge()
>>> report = evaluate(classifier, X, y, splitter=0.2)
>>> display = report.metrics.prediction_error()
>>> display.plot(kind="actual_vs_predicted")
set_style(*, policy='update', relplot_kwargs=None, perfect_model_kwargs=None)[source]#

Set the style parameters for the display.

Parameters:
policy{“override”, “update”}, default=”update”

Policy to use when setting the style parameters. If “override”, each provided group replaces the previous value. Omitted groups are left unchanged. If “update”, merge provided values into the existing settings. Passed keys replace the previous value. Nested dictionaries are merged the same way, so omitted keys are kept.

relplot_kwargsdict, default=None

Additional keyword arguments to be passed to seaborn.relplot() for rendering the scatter plot(s). Common options include palette, alpha, s, marker, etc.

perfect_model_kwargsdict, default=None

Additional keyword arguments to be passed to matplotlib.pyplot.plot() for drawing the perfect prediction line. Common options include color, alpha, linestyle, etc.

Returns:
None
Raises:
ValueError

If a style parameter is unknown.

static style_plot(plot_func)[source]#

Apply consistent style to skore displays.

This decorator: 1. Applies default style settings 2. Runs plot_func under plt.ioff() so figures are not shown until returned 3. Calls Figure.tight_layout() on the returned figure when applicable 4. Restores the original style settings

Parameters:
plot_funccallable

The plot function to be decorated.

Returns:
callable

The decorated plot function.