Search code examples
pythonmachine-learningnumbashap

shap : SystemError: initialization of _internal failed without raising an exception


I am tryring to use shap to get feature importance, but it fails at import:

import shap

Error:

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

How to resolve this?

python version : 3.9.13

shap version : 0.40.0


Solution

  • As per Hiran's comment in the question, it also worked for me. install shap again after uninstall it.

    pip uninstall shap
    
    pip install shap