You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To help control the scope of sklearn.plot, I propose we only do plotting on the axes level and not the figure level. The user would pass in the axes as a keyword. As a convenience, the default of axes will be None. Only in this case, will the plotting function generate a axes/figure to plot on.
Thanks for opening this issue, ping @jnothman@amueller@GaelVaroquaux according to gitter #8425 is not related to Decision Regions of Classifiers,?
I prefer to move plot_tree and plot_partial_dependence to sklearn.plot and solve #13335 in 0.21 (maybe introduce a function to plot the decision boundary, since it's important and not easy for beginners IMO). What do others think?
To help control the scope of sklearn.plot, I propose we only do plotting on the axes level and not the figure level. The user would pass in the axes as a keyword. As a convenience, the default of axes will be None. Only in this case, will the plotting function generate a axes/figure to plot on.
Good idea, but not consistent with existing functions (plot_tree and plot_partial_dependence), right?
There are cases where you need to output/modify a figure, such as with
multiple subplots (see seaborn's facet plots etc, and upsetplot for
example). Can you give reasons why you want to limit it to axes?
Good idea, but not consistent with existing functions (plot_tree and plot_partial_dependence), right?
@qinhanmin2014plot_tree does not seem to adjust the figure. plot_partial_dependence does make multiple plots based on features. Although, it can be refactored into an axes level plot. A user would need to call plot_partial_dependence multiple times giving it different axes (and features).
Can you give reasons why you want to limit it to axes?
@jnothman Seaborn has documentation that clearly separates "figure-level" plot and "axes-level" plots. If we can properly document this behavior in scikit-learn, it is possible to have these "figure-level" plots. My biggest concern with "figure-level" plots, is they are harder to maintain and test. There will be elements from one axes that may overlap with another axes. Although, we can work around this by structuring figures in such a way that overlapping happens less often.
In terms of testing, we can go the way of seaborn and test directly matplotlib objects or the yellowbrick way where we do pixel level testing. I tend to favor the testing the matplotlib objects.
+1 for containing the functions accessing matplotlib in a common subpackage, or, on a module in each subpackage (sklearn.linear_models.plot, sklearn.ensemble.plot).
As mentioned by @thomasjpfan, only accessing axes makes it easier to test.
Also, a long time ago, there was discussion in the ecosystem to give other plotting backends an "Axes"-like object for compatibility. I don't know where that went. A quick Googling doesn't show much. The closest is plotly.tools.mpl_to_plotly, which doesn't really need this restriction, so I think that argument is vain.
maybe introduce a function to plot the decision boundary, since it's important and not easy for beginners IMO
I agree but I also think that showing the users how to plot results such as decision boundaries is one of the goals of the examples.
If I want a quick first plot of a result, plotting functions are great, especially for complicated plots such as plotting a tree, but I very often like to tweak the plot to my needs and for that reason I prefer to rely on existing examples and modify the code.
no strong opinion, will vote +1 for both name. Maybe plot is more straightforward?
Again I'm interested in creating the new module before 0.21 and move plot_tree and plot_partial_dependence there. Ideally we should also reach consensus on the API (e.g., axes level/ figure level).
We may want inspect tools that offer plotting as an option. For example, print the characteristics of a tree (number of nodes, leaves, split points, etc.) and optionally plot it with matplotlib.
I would be in favor of using axes instead of figures, as suggested (sigh, I'll need to change PDPs again). It's easier for us to support and test. It's a little more work for the users, but it also allows for more control.
> IMO inspect is more versatile than plot
no strong opinion, will vote +1 for both name. Maybe plot is more straightforward?
"inspect" is loaded in Python (it's a module in the standard library). I
would avoid using the same name.
Again I'm interested in creating the new module before 0.21 and move plot_tree and plot_partial_dependence there. Ideally we should also reach consensus on the API (e.g., axes level/ figure level).
This shouldn't delay 0.21. Our goal is to release early, and hopefully
release early again.
FWIW, I'd also prefer plot to inspect, since it's more intuitive for most users to find it. People are more likely trying to plot their models than inspect their models (when searching on search engines for instance, or looking at the possible autocomplete options on their IDE).
Gael's suggestion of a public plot submodule on each subpackage is worth considering.
If so, where shall we put plot_decision_boundary?
Regarding #12599, @NicolasHug I doubt whether partial_dependence should be in the new module. (i.e., ensemble.partial_dependence + plot.plot_partial_dependence)
@qinhanmin2014 no, many things can not easily be changed afterwards, and we don't need to think about all the formatting necessarily ourselves, but we should allow users to plot something again. It will basically happen any time you do a plot. And having to subsample datasets every time I want to do a plot is a bit annoying. And if I later change my mind I will still need to recompute.
Basically the point is that you can't usually anticipate what exactly you want in your exploratory analysis, and having to recompute everything to change a visualization doesn't seem great.
@qinhanmin2014 no, many things can not easily be changed afterwards, and we don't need to think about all the formatting necessarily ourselves, but we should allow users to plot something again. It will basically happen any time you do a plot. And having to subsample datasets every time I want to do a plot is a bit annoying. And if I later change my mind I will still need to recompute.
Yes, I know it might be useful, but the main issue here is that we don't have a clean way to support this functionality, and I guess most plotting functions do not require much calculation?
I like that we're discussing this with a little more grounding, but tbh I'm
still not entirely convinced that we even need to have plot in the import
path at all. After all, we seem to have plot_ as a prefix for the
functions. The question also relates to plot_tree: why *should* it be
separated from other export and textual visualisation code?
@qinhanmin2014 I don't think "we don't have a good API yet" is a good reason.
And partial dependence, permutation importance, learning curves, validation curves and results of GridSearchCV and RandomizedSearchCV are all common examples that take a lot of computation. Though for gridsearchcv and randomizedsearchcv the obvious thing would be to pass either the object or the cv_results_, doing the work inside the plotting function in those cases seems nonsensical. I'm not entirely sure about learning curves and validation curves tbh.
@jnothman I think @GaelVaroquaux wanted to keep the matplotlib dependency confined to a module and that was one of the main motivations? I don't really have very coherent thoughts about this yet.
And partial dependence, permutation importance, learning curves, validation curves and results of GridSearchCV and RandomizedSearchCV are all common examples that take a lot of computation.
Thanks, I now realized that I'm wrong :)
Though I'm still unable to understand why it's important to provide users with a way to plot without recomputing. But if others think so and there's a good way, I'll vote +1.
I like that we're discussing this with a little more grounding, but tbh I'm
still not entirely convinced that we even need to have plot in the import
path at all. After all, we seem to have plot_ as a prefix for the
functions. The question also relates to plot_tree: why should it be
separated from other export and textual visualisation code?
Yes this can also be an option. If so, we can mention that all the functions which start with plot_ requires matplotlib. Another advantage of this option is that we don't need to move existing functions.
Ok, unless someone disagrees with this in the following days, I'm going to update the PDP PR and:
put both partial_dependence and plot_partial_dependence in sklearn.inspection
make plot_partial_dependence return a bunch with the fig and ax objects as attributes (right now it returns them in a tuple). This way, we'll be able to keep these 2 functions backward compatible when we implement the second option from Add a sklearn.plot Module #13448 (comment)
Can we make the final decision here?
Proposal agreed by @jnothman , @NicolasHug and me (apologies if I'm wrong): sklearn.XXX.plot_YYY (support from sklearn.XXX import plot_YYY). We'll mention that all the functions which start with plot_ requires matplotlib.
A major advantage of this proposal is that we don't need to move existing functions.
Activity
qinhanmin2014 commentedon Mar 14, 2019
Thanks for opening this issue, ping @jnothman @amueller @GaelVaroquaux according to gitter
#8425 is not related to Decision Regions of Classifiers,?
I prefer to move plot_tree and plot_partial_dependence to sklearn.plot and solve #13335 in 0.21 (maybe introduce a function to plot the decision boundary, since it's important and not easy for beginners IMO). What do others think?
Good idea, but not consistent with existing functions (plot_tree and plot_partial_dependence), right?
jnothman commentedon Mar 14, 2019
thomasjpfan commentedon Mar 15, 2019
@qinhanmin2014
plot_treedoes not seem to adjust the figure.plot_partial_dependencedoes make multiple plots based onfeatures. Although, it can be refactored into an axes level plot. A user would need to callplot_partial_dependencemultiple times giving it different axes (and features).@jnothman Seaborn has documentation that clearly separates "figure-level" plot and "axes-level" plots. If we can properly document this behavior in scikit-learn, it is possible to have these "figure-level" plots. My biggest concern with "figure-level" plots, is they are harder to maintain and test. There will be elements from one axes that may overlap with another axes. Although, we can work around this by structuring figures in such a way that overlapping happens less often.
In terms of testing, we can go the way of seaborn and test directly matplotlib objects or the yellowbrick way where we do pixel level testing. I tend to favor the testing the matplotlib objects.
GaelVaroquaux commentedon Mar 15, 2019
My 2 cents:
+1 for containing the functions accessing matplotlib in a common subpackage, or, on a module in each subpackage (sklearn.linear_models.plot, sklearn.ensemble.plot).
As mentioned by @thomasjpfan, only accessing axes makes it easier to test.
Also, a long time ago, there was discussion in the ecosystem to give other plotting backends an "Axes"-like object for compatibility. I don't know where that went. A quick Googling doesn't show much. The closest is plotly.tools.mpl_to_plotly, which doesn't really need this restriction, so I think that argument is vain.
albertcthomas commentedon Mar 15, 2019
I agree but I also think that showing the users how to plot results such as decision boundaries is one of the goals of the examples.
If I want a quick first plot of a result, plotting functions are great, especially for complicated plots such as plotting a tree, but I very often like to tweak the plot to my needs and for that reason I prefer to rely on existing examples and modify the code.
NicolasHug commentedon Mar 19, 2019
Regarding the name of the module, IMO
inspectis more versatile thanplot:inspectqinhanmin2014 commentedon Mar 19, 2019
no strong opinion, will vote +1 for both name. Maybe plot is more straightforward?
Again I'm interested in creating the new module before 0.21 and move plot_tree and plot_partial_dependence there. Ideally we should also reach consensus on the API (e.g., axes level/ figure level).
NicolasHug commentedon Mar 19, 2019
Other point in favor of
inspect:We may want inspect tools that offer plotting as an option. For example, print the characteristics of a tree (number of nodes, leaves, split points, etc.) and optionally plot it with matplotlib.
I would be in favor of using axes instead of figures, as suggested (sigh, I'll need to change PDPs again). It's easier for us to support and test. It's a little more work for the users, but it also allows for more control.
GaelVaroquaux commentedon Mar 19, 2019
thomasjpfan commentedon Mar 19, 2019
I propose
model_inspection. It goes well with ourmodel_selectionname.NicolasHug commentedon Mar 19, 2019
We might want to inspect something that's not a model (encoder, preprocessor, grid search results...)
inspectionthen?jnothman commentedon Mar 20, 2019
adrinjalali commentedon Mar 20, 2019
FWIW, I'd also prefer
plottoinspect, since it's more intuitive for most users to find it. People are more likely trying to plot their models than inspect their models (when searching on search engines for instance, or looking at the possible autocomplete options on their IDE).qinhanmin2014 commentedon Mar 20, 2019
If so, where shall we put
plot_decision_boundary?Regarding #12599, @NicolasHug I doubt whether
partial_dependenceshould be in the new module. (i.e., ensemble.partial_dependence + plot.plot_partial_dependence)GaelVaroquaux commentedon Mar 20, 2019
31 remaining items
qinhanmin2014 commentedon Apr 3, 2019
And @amueller we’ll support passing axes, so users can easily adjust the plot after they call the plotting functions?
amueller commentedon Apr 3, 2019
@qinhanmin2014 no, many things can not easily be changed afterwards, and we don't need to think about all the formatting necessarily ourselves, but we should allow users to plot something again. It will basically happen any time you do a plot. And having to subsample datasets every time I want to do a plot is a bit annoying. And if I later change my mind I will still need to recompute.
Basically the point is that you can't usually anticipate what exactly you want in your exploratory analysis, and having to recompute everything to change a visualization doesn't seem great.
qinhanmin2014 commentedon Apr 4, 2019
Yes, I know it might be useful, but the main issue here is that we don't have a clean way to support this functionality, and I guess most plotting functions do not require much calculation?
jnothman commentedon Apr 4, 2019
amueller commentedon Apr 4, 2019
@qinhanmin2014 I don't think "we don't have a good API yet" is a good reason.
And partial dependence, permutation importance, learning curves, validation curves and results of GridSearchCV and RandomizedSearchCV are all common examples that take a lot of computation. Though for gridsearchcv and randomizedsearchcv the obvious thing would be to pass either the object or the
cv_results_, doing the work inside the plotting function in those cases seems nonsensical. I'm not entirely sure about learning curves and validation curves tbh.amueller commentedon Apr 4, 2019
@jnothman I think @GaelVaroquaux wanted to keep the matplotlib dependency confined to a module and that was one of the main motivations? I don't really have very coherent thoughts about this yet.
qinhanmin2014 commentedon Apr 4, 2019
Thanks, I now realized that I'm wrong :)
Though I'm still unable to understand why it's important to provide users with a way to plot without recomputing. But if others think so and there's a good way, I'll vote +1.
Yes this can also be an option. If so, we can mention that all the functions which start with
plot_requires matplotlib. Another advantage of this option is that we don't need to move existing functions.thomasjpfan commentedon Apr 16, 2019
Going over this discussion, I agree with not adding a
sklearn.plotmodule, and use the prefixplot_to signal amatplotlibrequirement.For example, in #12599,
partial_dependenceandplot_partial_dependencewill be placed ininspection.NicolasHug commentedon Apr 16, 2019
Ok, unless someone disagrees with this in the following days, I'm going to update the PDP PR and:
partial_dependenceandplot_partial_dependenceinsklearn.inspectionplot_partial_dependencereturn a bunch with thefigandaxobjects as attributes (right now it returns them in a tuple). This way, we'll be able to keep these 2 functions backward compatible when we implement the second option from Add a sklearn.plot Module #13448 (comment)qinhanmin2014 commentedon Apr 17, 2019
Can we make the final decision here?
Proposal agreed by @jnothman , @NicolasHug and me (apologies if I'm wrong): sklearn.XXX.plot_YYY (support from sklearn.XXX import plot_YYY). We'll mention that all the functions which start with plot_ requires matplotlib.
A major advantage of this proposal is that we don't need to move existing functions.
agramfort commentedon Apr 17, 2019
jnothman commentedon Apr 18, 2019
NicolasHug commentedon Apr 18, 2019
FYI, I'm adding
sklearn.utils.check_matplotlib_supportin #12599qinhanmin2014 commentedon Apr 18, 2019
That's great! Thanks.