如何为Python安装SHAP(Shapley)

时间:2018-06-07 02:03:16

标签: python install xgboost

尝试使用

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

3 个答案:

答案 0 :(得分:1)

你是不是想要整齐地安装(https://pypi.org/project/Shapely/)? 在python中,您可以通过pip install shapely

进行整形安装

对于Windows shapley,可以通过从http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely下载.whl来安装

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,你可以看到这个stackoverflow.com/questions/35139108 / ...或者只是做conda install py-xgboost

答案 1 :(得分:1)

您是否要安装shap-一个用于解释机器学习模型的库?如果是这样,请使用

pip install shap

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

答案 2 :(得分:0)

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

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