如何为 Python 安装 SHAP (Shapley)

How to install SHAP (Shapley) for Python

尝试使用

安装 Shapley 包(在 R 中可用)
install shap

但出现错误:

Building wheels for collected packages: shap, iml
Running setup.py bdist_wheel for shap ... error
Complete output from command C:\Users\Toly_Novik\Anaconda3\python.exe -u -c     "import setuptools, tokenize;__file__='C:\Users\TOLY_N~1\AppData\Local\Temp  \pip-install-o0p96nl3\shap\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d C:\Users\TOLY_N~1\AppData\Local\Temp\pip-wheel-538qnmm2 --python-tag cp36:
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-3.6
creating build\lib.win-amd64-3.6\shap
copying shap\datasets.py -> build\lib.win-amd64-3.6\shap
copying shap\plots.py -> build\lib.win-amd64-3.6\shap
copying shap\__init__.py -> build\lib.win-amd64-3.6\shap
creating build\lib.win-amd64-3.6\shap\explainers
copying shap\explainers\ime.py -> build\lib.win-amd64-3.6\shap\explainers
copying shap\explainers\kernel.py -> build\lib.win-amd64-3.6\shap\explainers
copying shap\explainers\mimic.py -> build\lib.win-amd64-3.6\shap\explainers
copying shap\explainers\pytree.py -> build\lib.win-amd64-3.6\shap\explainers
copying shap\explainers\tree.py -> build\lib.win-amd64-3.6\shap\explainers
copying shap\explainers\__init__.py -> build\lib.win-amd64-3.6 \shap\explainers
running build_ext
numpy.get_include() C:\Users\Toly_Novik\Anaconda3\lib\site-packages\numpy\core\include
building 'shap._cext' extension
error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual  C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

同样的故事 安装 xgboost

您是要安装得体 (https://pypi.org/project/Shapely/) 吗? 在 python 中,您可以通过 pip install shapely

进行匀称安装

对于 windows 可以通过从 http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely 下载 .whl 并执行

安装 shapley

pip install <name of whl file>

或者如果您使用的是 anaconda,则可以使用 conda-forge 来保持身材

conda config --add channels conda-forge conda install shapely


要安装 xgboost,请参阅 http://xgboost.readthedocs.io/en/latest/python/python_intro.html 为此,您可能需要 gcc(c/c++ 编译器)或等效的 Microsoft 替代方案。

对于带有 conda 的 xgboost,你可以看到这个 Whosebug。com/questions/35139108/… 或者简单地做 conda install py-xgboost

您是否正在尝试安装 shap - 一个用于解释机器学习模型的库?如果是这样使用

pip install shap

有关详细信息,请参阅 shap 文档:https://pypi.org/project/shap/

pip install git+https://github.com/slundberg/shap.git 

仅使用 pip install 对我不起作用(错误 运行 测试),conda 方法也没有。