explainy is a library for generating explanations for machine learning models in Python. It uses methods from Machine Learning Explainability and provides a standardized API to create feature importance explanations for samples. The explanations are generated in the form of plots and text.
Project description
"""
explainy - black-box model explanations for humans
explainy is a library for generating explanations for machine learning models in Python. It uses methods from Machine Learning Explainability and provides a standardized API to create feature importance explanations for samples. The explanations are generated in the form of plots and text.
explainy comes with four different algorithms to create either global or local and contrastive or non-contrastive machine learning model explanations.
Documentation
https://explainy.readthedocs.io
Install explainy
pip install explainy
Usage
import pandas as pd
from sklearn.datasets import load_diabetes
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import train_test_split
diabetes = load_diabetes()
X_train, X_test, y_train, y_test = train_test_split(
diabetes.data, diabetes.target, random_state=0
)
X_test = pd.DataFrame(X_test, columns=diabetes.feature_names)
y_test = pd.DataFrame(y_test)
model = RandomForestRegressor(random_state=0).fit(X_train, y_train)
from explainy.explanation.permutation_explanation import PermutationExplanation
number_of_features = 4
sample_index = 1
explainer = PermutationExplanation(
X_test, y_test, model, number_of_features
)
explanation = explainer.explain(
sample_index, separator='\n'
)
print(explanation)
The RandomForestRegressor used 10 features to produce the predictions. The prediction of this sample was 251.8.
The feature importance was calculated using the Permutation Feature Importance method.
The four features which were most important for the predictions were (from highest to lowest): 'bmi' (0.15), 's5' (0.12), 'bp' (0.03), and 'age' (0.02).
explainer.plot()
explainer.save(sample_index)
Model Explanations
Method | Type | Explanations | Classification | Regression |
---|---|---|---|---|
Permutation Feature Importance | Non-contrastive | global | :star: | :star: |
Shapley Values | Non-contrastive | local | :star: | :star: |
Global Surrogate Model | Contrastive | global | :star: | :star: |
Counterfactual Example | Contrastive | local | :star: | :star: |
Description
- global:
- local:
- contrastive:
- non-contrastive:
Features
TODO
Explanations
Permutation Feature Importance
Permutation feature importance measures the increase in the prediction error of the model after we permuted the feature's values, which breaks the relationship between the feature and the true outcome [1].
Characteristics
- global
- non-contrastive
Shapley Values
A prediction can be explained by assuming that each feature value of the instance is a "player" in a game where the prediction is the payout. Shapley values (a method from coalitional game theory) tells us how to fairly distribute the "payout" among the features. The Shapley value is the average marginal contribution of a feature value across all possible coalitions [1].
Characteristics
- local
- non-contrastive
Counterfactual explanations
Counterfactual explanations tell us how the values of an instance have to change to significantly change its prediction. A counterfactual explanation of a prediction describes the smallest change to the feature values that changes the prediction to a predefined output. By creating counterfactual instances, we learn about how the model makes its predictions and can explain individual predictions [1].
Characteristics
- local
- contrastive
Global Surrogate Model (Decision Tree)
A global surrogate model is an interpretable model that is trained to approximate the predictions of a black box model. We can draw conclusions about the black box model by interpreting the surrogate model [1].
Characteristics
- global
- contrastive
Source
[1] Molnar, Christoph. "Interpretable machine learning. A Guide for Making Black Box Models Explainable", 2019. https://christophm.github.io/interpretable-ml-book/
Authors
- Mauro Luzzatto - Maurol
"""
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for explainy-0.1.8-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bed24ca6f9bc303da6d5e07fd410354a0e6480dd65ce62af57b56f1f0aece55b |
|
MD5 | 0ade29d3a38f8b156a9db8a3dc7a51cf |
|
BLAKE2b-256 | 7fbd5caef95852577fd1959b10dc9c4ee117924e5f65693547bface436e4ca02 |