python shap:系统错误:初始化_internal失败,未引发异常

osh3o9ms  于 2023-02-02  发布在  Python
关注(0)|答案(1)|浏览(718)

我正在使用一个SVC来预测一个目标。我正在尝试使用shap来获得特征的重要性。但是它失败了。
下面是我从shap的官方文档中复制的简单代码:

import shap
svc_linear = SVC(C=1.2, probability=True)
svc_linear.fit(X_train, Y_train)
explainer = shap.KernelExplainer(svc_linear.predict_proba, X_train)
shap_values = explainer.shap_values(X_test)
shap.force_plot(explainer.expected_value[0], shap_values[0], X_test)

但我得到了这个

---------------------------------------------------------------------------
SystemError                               Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_11012\3923049429.py in <module>
----> 1 import shap
      2 svc_linear = SVC(C=1.2, probability=True)
      3 svc_linear.fit(X_train, Y_train)
      4 explainer = shap.KernelExplainer(svc_linear.predict_proba, X_train)
      5 shap_values = explainer.shap_values(X_test)

~\Anaconda3\lib\site-packages\shap\__init__.py in <module>
     10     warnings.warn("As of version 0.29.0 shap only supports Python 3 (not 2)!")
     11 
---> 12 from ._explanation import Explanation, Cohorts
     13 
     14 # explainers

~\Anaconda3\lib\site-packages\shap\_explanation.py in <module>
     10 from slicer import Slicer, Alias, Obj
     11 # from ._order import Order
---> 12 from .utils._general import OpChain
     13 from .utils._exceptions import DimensionError
     14 

~\Anaconda3\lib\site-packages\shap\utils\__init__.py in <module>
----> 1 from ._clustering import hclust_ordering, partition_tree, partition_tree_shuffle, delta_minimization_order, hclust
      2 from ._general import approximate_interactions, potential_interactions, sample, safe_isinstance, assert_import, record_import_error
      3 from ._general import shapley_coefficients, convert_name, format_value, ordinal_str, OpChain, suppress_stderr
      4 from ._show_progress import show_progress
      5 from ._masked_model import MaskedModel, make_masks

~\Anaconda3\lib\site-packages\shap\utils\_clustering.py in <module>
      2 import scipy as sp
      3 from scipy.spatial.distance import pdist
----> 4 from numba import jit
      5 import sklearn
      6 import warnings

~\Anaconda3\lib\site-packages\numba\__init__.py in <module>
     40 
     41 # Re-export vectorize decorators and the thread layer querying function
---> 42 from numba.np.ufunc import (vectorize, guvectorize, threading_layer,
     43                             get_num_threads, set_num_threads)
     44 

~\Anaconda3\lib\site-packages\numba\np\ufunc\__init__.py in <module>
      1 # -*- coding: utf-8 -*-
      2 
----> 3 from numba.np.ufunc.decorators import Vectorize, GUVectorize, vectorize, guvectorize
      4 from numba.np.ufunc._internal import PyUFunc_None, PyUFunc_Zero, PyUFunc_One
      5 from numba.np.ufunc import _internal, array_exprs

~\Anaconda3\lib\site-packages\numba\np\ufunc\decorators.py in <module>
      1 import inspect
      2 
----> 3 from numba.np.ufunc import _internal
      4 from numba.np.ufunc.parallel import ParallelUFuncBuilder, ParallelGUFuncBuilder
      5 

SystemError: initialization of _internal failed without raising an exception

我不知道为什么,有人知道吗?
附言:
python版本:3.9.13
形状版本:0.40.0

au9on6nz

au9on6nz1#

根据希兰在问题中的评论,它也为我工作。卸载后再次安装shap。
pip卸载形状
管道安装形状

相关问题