简体   繁体   中英

ModuleNotFoundError: No module named 'sklearn.inspection'

I'm following the example in sklearn.inspection.permutation_importance .

from sklearn.linear_model import LogisticRegression
from sklearn.inspection import permutation_importance
X = [[1, 9, 9],[1, 9, 9],[1, 9, 9],
     [0, 9, 9],[0, 9, 9],[0, 9, 9]]
y = [1, 1, 1, 0, 0, 0]
clf = LogisticRegression().fit(X, y)
result = permutation_importance(clf, X, y, n_repeats=10,
                                random_state=0)
result.importances_mean
result.importances_std

I try to import permutation_importance from sklearn.inspection , but I get

Traceback (most recent call last):
  File "train.py", line 20, in <module>
    from sklearn.inspection import permutation_importance
ModuleNotFoundError: No module named 'sklearn.inspection'

My sklearn version is 0.20.3

import sklearn
print(sklearn.__version__)

# result: 0.20.3

sklearn.inspection is a new subpackage introduced in Version 0.21.0 .

I need to execute pip install --upgrade scikit-learn to upgrade the sklearn to the newest version.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM