天天看點

Py之eli5:eli5庫的簡介、安裝、使用方法之詳細攻略

Py之eli5:eli5庫的簡介、安裝、使用方法之詳細攻略

目錄

​​eli5庫的簡介​​

​​eli5庫的安裝​​

​​pip安裝eli5過程​​

​​conda安裝eli5過程​​

​​eli5庫的使用方法​​

eli5庫的簡介

幫助調試機器學習分類器并解釋它們的預測。ELI5是一個Python庫,它允許使用統一的API可視化和調試各種機器學習模型。它内置了對幾種ML架構的支援,并提供了一種解釋黑盒模型的方法。

      它支援以下機器學習架構和包:

(1) 、scikit-learn-目前,ELI5允許解釋scikit-learn線性分類器和回歸器的權重和預測,将決策樹列印為文本或SVG,顯示特征的重要性,并解釋決策樹和基于樹的集合的預測。ELI5了解來自scikit-learn的文本處理實用程式,并能相應地高亮顯示文本資料。支援Pipeline和FeatureUnion。它還允許通過撤銷哈希來調試包含HashingVectorizer的scikit-learn管道。

(2)、Keras -通過 Grad-CAM 可視化解釋圖像分類器的預測。

(3)、xgboost -顯示特征重要性并解釋XGBClassifier, XGBRegressor和xgboost. booster的預測。

(4)、LightGBM -顯示特征重要性,解釋LGBMClassifier, LGBMRegressor和LightGBM . booster的預測。

(5)、CatBoost -顯示CatBoostClassifier、CatBoostRegressor和CatBoost. CatBoost的特征重要性。

(6)、lightning -解釋lightning 分類器和回歸器的權重和預測。

(7) 、sklearn-crfsuite-ELI5允許檢查sklearn_crfsuite.CRF模型的權重。

      ELI5還實作了幾種用于檢查黑盒模型的算法(參見檢查黑盒估計器):

(1), TextExplainer允許使用LIME算法解釋任何文本分類器的預測(Ribeiro et al., 2016)。有一些實用程式可以将LIME與非文本資料和任意黑盒分類器一起使用,但是這個特性目前還處于試驗階段。

(2)、置換重要性方法可用于計算黑盒估計器的特征重要性。

官方文檔:​​Welcome to ELI5’s documentation! — ELI5 0.11.0 documentation​​

eli5庫的安裝

pip安裝eli5過程

pip install eli5

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple eli5      

conda安裝eli5過程

(base) PS C:\Users\99386> conda install eli5
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
PackagesNotFoundError: The following packages are not available from current channels:
  - eli5
Current channels:
  - https://repo.anaconda.com/pkgs/main/win-64
  - https://repo.anaconda.com/pkgs/main/noarch
  - https://repo.anaconda.com/pkgs/r/win-64
  - https://repo.anaconda.com/pkgs/r/noarch
  - https://repo.anaconda.com/pkgs/msys2/win-64
  - https://repo.anaconda.com/pkgs/msys2/noarch
To search for alternate channels that may provide the conda package you're
looking for, navigate to
    https://anaconda.org
and use the search bar at the top of the page.

(base) PS C:\Users\99386> conda config --show channels
channels:
  - defaults
(base) PS C:\Users\99386> conda config --show channels
channels:
  - defaults
(base) PS C:\Users\99386> conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
(base) PS C:\Users\99386> conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
(base) PS C:\Users\99386> conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
(base) PS C:\Users\99386>
(base) PS C:\Users\99386> conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
(base) PS C:\Users\99386> conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
(base) PS C:\Users\99386> conda config --set show_channel_urls yes
(base) PS C:\Users\99386> conda config --show channels
channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - defaults
(base) PS C:\Users\99386> conda install eli5
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 4.12.0
  latest version: 4.13.0
Please update conda by running
    $ conda update -n base -c defaults conda
## Package Plan ##
  environment location: D:\ProgramData\Anaconda3
  added / updated specs:
    - eli5
The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    ca-certificates-2022.3.29  |       haa95532_1         122 KB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
    certifi-2021.10.8          |   py39haa95532_2         152 KB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
    conda-4.12.0               |   py39hcbf5309_0         1.0 MB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
    eli5-0.11.0                |     pyhd8ed1ab_0          76 KB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
    graphviz-2.38.0            |    h6538335_1011        41.0 MB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
    openssl-1.1.1n             |       h2bbff1b_0         4.8 MB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
    python-graphviz-0.16       |     pyhd3deb0d_1          20 KB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
    python_abi-3.9             |           2_cp39           4 KB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
    singledispatch-3.6.1       |     pyh44b312d_0          12 KB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
    ------------------------------------------------------------
                                           Total:        47.2 MB
The following NEW packages will be INSTALLED:
  eli5               anaconda/cloud/conda-forge/noarch::eli5-0.11.0-pyhd8ed1ab_0
  graphviz           anaconda/cloud/conda-forge/win-64::graphviz-2.38.0-h6538335_1011
  python-graphviz    anaconda/cloud/conda-forge/noarch::python-graphviz-0.16-pyhd3deb0d_1
  python_abi         anaconda/cloud/conda-forge/win-64::python_abi-3.9-2_cp39
  singledispatch     anaconda/cloud/conda-forge/noarch::singledispatch-3.6.1-pyh44b312d_0

The following packages will be SUPERSEDED by a higher-priority channel:

  ca-certificates                                 pkgs/main --> anaconda/pkgs/main
  certifi                                         pkgs/main --> anaconda/pkgs/main
  conda              pkgs/main::conda-4.12.0-py39haa95532_0 --> anaconda/cloud/conda-forge::conda-4.12.0-py39hcbf5309_0
  openssl                                         pkgs/main --> anaconda/pkgs/main
Proceed ([y]/n)? y
Downloading and Extracting Packages
python-graphviz-0.16 | 20 KB     | ################################################################################################################################################# | 100%
ca-certificates-2022 | 122 KB    | ################################################################################################################################################# | 100%
singledispatch-3.6.1 | 12 KB     | ################################################################################################################################################# | 100%
python_abi-3.9       | 4 KB      | ################################################################################################################################################# | 100%
openssl-1.1.1n       | 4.8 MB    | ################################################################################################################################################# | 100%
eli5-0.11.0          | 76 KB     | ################################################################################################################################################# | 100%
conda-4.12.0         | 1.0 MB    | ################################################################################################################################################# | 100%
graphviz-2.38.0      | 41.0 MB   | ################################################################################################################################################# | 100%
certifi-2021.10.8    | 152 KB    | ################################################################################################################################################# | 100%
Preparing transaction: done
Verifying transaction: failed
EnvironmentNotWritableError: The current user does not have write permissions to the target environment.
  environment location: D:\ProgramData\Anaconda3      

eli5庫的使用方法