Python package SHAP import

筅森魡賤 提交于 2021-01-28 11:52:39

问题


I installed Python package shap for plotting.

conda install -c conda-forge shap

After installing, I import shap in jupyter notebook but got error.

import shap

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-132-efbb001a1501> in <module>
----> 1 import shap

~\AppData\Local\Continuum\anaconda3\lib\site-packages\shap\__init__.py in <module>
      3 __version__ = '0.29.3'
      4 
----> 5 from .explainers.kernel import KernelExplainer, kmeans
      6 from .explainers.sampling import SamplingExplainer
      7 from .explainers.tree import TreeExplainer, Tree

~\AppData\Local\Continuum\anaconda3\lib\site-packages\shap\explainers\kernel.py in <module>
      9 import warnings
     10 from sklearn.linear_model import LassoLarsIC, Lasso, lars_path
---> 11 from sklearn.cluster import KMeans
     12 from tqdm.auto import tqdm
     13 from .explainer import Explainer

~\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\cluster\__init__.py in <module>
      8                           estimate_bandwidth, get_bin_seeds)
      9 from .affinity_propagation_ import affinity_propagation, AffinityPropagation
---> 10 from .hierarchical import (ward_tree, AgglomerativeClustering, linkage_tree,
     11                            FeatureAgglomeration)
     12 from .k_means_ import k_means, KMeans, MiniBatchKMeans

~\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\cluster\hierarchical.py in <module>
     23 from ._feature_agglomeration import AgglomerationTransform
     24 from ..utils.fast_dict import IntFloatDict
---> 25 from ..utils.fixes import _astype_copy_false
     26 from ..utils import deprecated
     27

ImportError: cannot import name '_astype_copy_false' from 'sklearn.utils.fixes' (C:\Users\username\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\utils\fixes.py)

Any suggestion?

import sklearn
print('The scikit-learn version is {}.'.format(sklearn.__version__))
The scikit-learn version is 0.21.2.

# TODO: replace by copy=False, when only scipy > 1.1 is supported.
def _astype_copy_false(X):
    """Returns the copy=False parameter for
    {ndarray, csr_matrix, csc_matrix}.astype when possible,
    otherwise don't specify
    """
    if sp_version >= (1, 1) or not sp.issparse(X):
        return {'copy': False}
    else:
        return {}

来源:https://stackoverflow.com/questions/56936651/python-package-shap-import

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!