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.
Examples
>>> 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:
“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).
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.
Examples
>>> 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:
“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).
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.
Examples
>>> 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:
“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).
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.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4