【问题标题】:shap : SystemError: initialization of _internal failed without raising an exceptionshap:SystemError:_internal 的初始化失败但未引发异常
【发布时间】:2023-02-02 12:11:02
【问题描述】:

我正在使用 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

我不知道为什么?有谁知道为什么?

附言:

蟒蛇版本:3.9.13

形状版本:0.40.0

【问题讨论】:

  • 无法重现给定代码的错误。看起来错误发生在导入包时。您是否尝试过卸载软件包并重新安装?
  • 你好,谢谢你的评论。我做到了,我像天堂一样工作。

标签: python machine-learning jupyter-notebook shap svc


【解决方案1】:

根据 Hiran 在问题中的评论,它也对我有用。 卸载后重新安装 shap。

pip 卸载 shap

pip 安装 shap

【讨论】:

    猜你喜欢
    • 2023-02-19
    • 2023-02-10
    • 2017-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-09
    • 2018-03-23
    • 2014-12-15
    相关资源
    最近更新 更多