问题
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