Decisions boundary visualization.
It is recommended to use from_estimator to create a DecisionBoundaryDisplay. All parameters are stored as attributes.
Read more in the User Guide.
Added in version 1.1.
First output of meshgrid.
Second output of meshgrid.
Values of the response function.
Default label to place on x axis.
Default label to place on y axis.
QuadContourSet or QuadMesh
If plot_method is ‘contour’ or ‘contourf’, surface_ is a QuadContourSet. If plot_method is ‘pcolormesh’, surface_ is a QuadMesh.
Axes with decision boundary.
Figure containing the decision boundary.
See also
DecisionBoundaryDisplay.from_estimatorPlot decision boundary given an estimator.
>>> import matplotlib.pyplot as plt >>> import numpy as np >>> from sklearn.datasets import load_iris >>> from sklearn.inspection import DecisionBoundaryDisplay >>> from sklearn.tree import DecisionTreeClassifier >>> iris = load_iris() >>> feature_1, feature_2 = np.meshgrid( ... np.linspace(iris.data[:, 0].min(), iris.data[:, 0].max()), ... np.linspace(iris.data[:, 1].min(), iris.data[:, 1].max()) ... ) >>> grid = np.vstack([feature_1.ravel(), feature_2.ravel()]).T >>> tree = DecisionTreeClassifier().fit(iris.data[:, :2], iris.target) >>> y_pred = np.reshape(tree.predict(grid), feature_1.shape) >>> display = DecisionBoundaryDisplay( ... xx0=feature_1, xx1=feature_2, response=y_pred ... ) >>> display.plot() <...> >>> display.ax_.scatter( ... iris.data[:, 0], iris.data[:, 1], c=iris.target, edgecolor="black" ... ) <...> >>> plt.show()
Plot decision boundary given an estimator.
Read more in the User Guide.
Trained estimator used to plot the decision boundary.
Input data that should be only 2-dimensional.
Number of grid points to use for plotting decision boundary. Higher values will make the plot look nicer but be slower to render.
Extends the minimum and maximum values of X for evaluating the response function.
Plotting method to call when plotting the response. Please refer to the following matplotlib documentation for details: contourf, contour, pcolormesh.
Specifies whether to use predict_proba, decision_function, predict as the target response. If set to ‘auto’, the response method is tried in the following order: decision_function, predict_proba, predict. For multiclass problems, predict is selected when response_method="auto".
The class considered when plotting the decision. If None, estimator.classes_[1] is considered as the positive class for binary classifiers. Must have an explicit value for multiclass classifiers when response_method is ‘predict_proba’ or ‘decision_function’.
Added in version 1.4.
The label used for the x-axis. If None, an attempt is made to extract a label from X if it is a dataframe, otherwise an empty string is used.
The label used for the y-axis. If None, an attempt is made to extract a label from X if it is a dataframe, otherwise an empty string is used.
Axes object to plot on. If None, a new figure and axes is created.
Additional keyword arguments to be passed to the plot_method.
DecisionBoundaryDisplay
Object that stores the result.
See also
DecisionBoundaryDisplayDecision boundary visualization.
sklearn.metrics.ConfusionMatrixDisplay.from_estimatorPlot the confusion matrix given an estimator, the data, and the label.
sklearn.metrics.ConfusionMatrixDisplay.from_predictionsPlot the confusion matrix given the true and predicted labels.
>>> import matplotlib.pyplot as plt >>> from sklearn.datasets import load_iris >>> from sklearn.linear_model import LogisticRegression >>> from sklearn.inspection import DecisionBoundaryDisplay >>> iris = load_iris() >>> X = iris.data[:, :2] >>> classifier = LogisticRegression().fit(X, iris.target) >>> disp = DecisionBoundaryDisplay.from_estimator( ... classifier, X, response_method="predict", ... xlabel=iris.feature_names[0], ylabel=iris.feature_names[1], ... alpha=0.5, ... ) >>> disp.ax_.scatter(X[:, 0], X[:, 1], c=iris.target, edgecolor="k") <...> >>> plt.show()
Plot visualization.
Plotting method to call when plotting the response. Please refer to the following matplotlib documentation for details: contourf, contour, pcolormesh.
Axes object to plot on. If None, a new figure and axes is created.
Overwrite the x-axis label.
Overwrite the y-axis label.
Additional keyword arguments to be passed to the plot_method.
DecisionBoundaryDisplay
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.inspection.DecisionBoundaryDisplay.html