Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Outdated sklearn.inspection.plot_partial_dependence #629

Open
st0fm opened this issue Nov 26, 2023 · 1 comment
Open

Outdated sklearn.inspection.plot_partial_dependence #629

st0fm opened this issue Nov 26, 2023 · 1 comment

Comments

@st0fm
Copy link

st0fm commented Nov 26, 2023

The function sklearn.inspection.plot_partial_dependence is not implemented in newer scikit-learn versions.
For example, when trying to execute the partial dependence example from chapter 09_tabular.ipynb in "Model Interpretation -> Partial Dependence" I will get the following error:

from sklearn.inspection import plot_partial_dependence

fig,ax = plt.subplots(figsize=(12, 4))
plot_partial_dependence(m, valid_xs_final, ['YearMade','ProductSize'],
                        grid_resolution=20, ax=ax);


---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[331], line 1
----> 1 from sklearn.inspection import plot_partial_dependence
      3 fig,ax = plt.subplots(figsize=(12, 4))
      4 plot_partial_dependence(m, valid_xs_final, ['YearMade','ProductSize'],
      5                         grid_resolution=20, ax=ax);

ImportError: cannot import name 'plot_partial_dependence' from 'sklearn.inspection'

Tested with scikit-learn version:

!pip freeze | grep scikit-learn
scikit-learn==1.3.1

In the documetation of scikit-learn I can't find sklearn.inspection.plot_partial_dependence after version 1.1.

In the newer scikit versions (1.2 or 1.3) we can use sklearn.inspection.PartialDependenceDisplay.from_estimator instead

For example:

from sklearn.inspection import PartialDependenceDisplay

fig,ax = plt.subplots(figsize=(12, 4))
PartialDependenceDisplay.from_estimator(m, valid_xs_final, ['YearMade', 'ProductSize'], 
                                        grid_resolution=20, ax=ax)

References:

@mattsgarlata
Copy link

Thanks for filing this! It was a big help for me.

If the maintainers will accept a PR to fix this in chapter 9, I'd be happy to supply it. I'll wait until this PR is merged first though: #634

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants