Repository navigation
Description
Repeating this here from #33115 (comment):
There are two paths to create a DecisionBoundaryDisplay plot (we recommend the second, but the first is also possible):
display = DecisionBoundaryDisplay(...)
display.plot()
and
display = DecisionBoundaryDisplay.from_estimator(...)
# which internally calls `display.plot()`
This leads to inconsistent/duplicate parameter checking in both functions.
The only place where the first option is used in our repo is in the example for the class itself, and calling it requires calculating the grid response values from an estimator anyway.
scikit-learn/sklearn/inspection/_plot/decision_boundary.py
Lines 140 to 150 in 351280b
| >>> 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() |
So if I'm not mistaken, the public plot() function doesn't add much here, and removing it would simplify the code and make adding more functionality (like planned in #33115, #33094 and #27462) easier.
WDYT? @ogrisel @lucyleeow @ThexXTURBOXx
(and @adrinjalali @glemaitre just in case you have time to take a look)
Note: I did not check if the same applies to any other Display class yet.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
lucyleeow commentedon Feb 2, 2026
You raise a good point, and indeed
DecisionBoundaryDisplayis (I think) the only class that only has afrom_estimatormethod (and not afrom_predictionsor evenfrom_cv_resultsmethod).The other classes all have more than one method that ultimately calls
plotto make the plot.The first display class was added in #14357 , I haven't extensively dug through it but it should provide good background on why implementation/design decisions where made.
In particular, it was decided to have the
plotmethod because:I think for those reasons and to keep consistency between display classes we should keep plot.
Again I think delaying param validation to
plotis okay, as performance is probably not critical for plotting. Also take a look at the_BinaryClassifierCurveDisplayMixinclass, which I think does some standard param validation for each display method (e.g.,_validate_plot_params,_validate_from_predictions_paramsetc)AnneBeyer commentedon Feb 3, 2026
Thank you for the context! I suspected that there are more complex decisions behind it. I'll have a look at them and will close this issue again for now.