All Projects → MauroLuzzatto → explainy

MauroLuzzatto / explainy

Licence: MIT License
explainy is a Python library for generating machine learning model explanations for humans

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to explainy

Eli5
A library for debugging/inspecting machine learning classifiers and explaining their predictions
Stars: ✭ 2,477 (+17592.86%)
Mutual labels:  scikit-learn, explanation
Sklearn-Nature-Inspired-Algorithms
Nature-inspired algorithms for hyper-parameter tuning of Scikit-Learn models.
Stars: ✭ 16 (+14.29%)
Mutual labels:  scikit-learn
playground
A Streamlit application to play with machine learning models directly from the browser
Stars: ✭ 48 (+242.86%)
Mutual labels:  scikit-learn
sklearn-audio-classification
An in-depth analysis of audio classification on the RAVDESS dataset. Feature engineering, hyperparameter optimization, model evaluation, and cross-validation with a variety of ML techniques and MLP
Stars: ✭ 31 (+121.43%)
Mutual labels:  scikit-learn
osprey
🦅Hyperparameter optimization for machine learning pipelines 🦅
Stars: ✭ 71 (+407.14%)
Mutual labels:  scikit-learn
kdd99-scikit
Solutions to kdd99 dataset with Decision tree and Neural network by scikit-learn
Stars: ✭ 50 (+257.14%)
Mutual labels:  scikit-learn
Football Prediction Project
This project will pull past game data from api-football, and use these statistics to predict the outcome of future premier league matches through machine learning.
Stars: ✭ 44 (+214.29%)
Mutual labels:  scikit-learn
textlytics
Text processing library for sentiment analysis and related tasks
Stars: ✭ 25 (+78.57%)
Mutual labels:  scikit-learn
object detector
Object detector from HOG + Linear SVM framework
Stars: ✭ 24 (+71.43%)
Mutual labels:  scikit-learn
vector space modelling
NLP in python Vector Space Modelling and document classification NLP
Stars: ✭ 16 (+14.29%)
Mutual labels:  scikit-learn
mash 2016 sklearn intro
Material for the MASH course on introduction to scikit-learn
Stars: ✭ 16 (+14.29%)
Mutual labels:  scikit-learn
A-Detector
⭐ An anomaly-based intrusion detection system.
Stars: ✭ 69 (+392.86%)
Mutual labels:  scikit-learn
scikit-learn
به فارسی، برای مشارکت scikit-learn
Stars: ✭ 19 (+35.71%)
Mutual labels:  scikit-learn
IBM-final-project-Machine-Learning
Final project of IBM's course https://www.coursera.org/learn/machine-learning-with-python on coursera
Stars: ✭ 33 (+135.71%)
Mutual labels:  scikit-learn
Machine-Learning-in-Python-Workshop
My workshop on machine learning using python language to implement different algorithms
Stars: ✭ 89 (+535.71%)
Mutual labels:  scikit-learn
doubleml-for-py
DoubleML - Double Machine Learning in Python
Stars: ✭ 129 (+821.43%)
Mutual labels:  scikit-learn
books
A collection of online books for data science, computer science and coding!
Stars: ✭ 29 (+107.14%)
Mutual labels:  scikit-learn
reactnative-typescript
Playground and evolution of learnings done in react native with typescript
Stars: ✭ 28 (+100%)
Mutual labels:  explanation
machine-learning-course
Machine Learning Course @ Santa Clara University
Stars: ✭ 17 (+21.43%)
Mutual labels:  scikit-learn
machine-learning-scripts
Collection of scripts and tools related to machine learning
Stars: ✭ 60 (+328.57%)
Mutual labels:  scikit-learn

explainy - black-box model explanations for humans

pypi version travis codecov docs Supported versions Code style: black Imports: isort Downloads

explainy is a library for generating machine learning models explanations in Python. It uses methods from Machine Learning Explainability and provides a standardized API to create feature importance explanations for samples.

The API is inspired by scikit-learn and has three core methods explain(), plot() and, importance(). The explanations are generated in the form of texts and plots.

explainy comes with four different algorithms to create either global or local and contrastive or non-contrastive model explanations.

Method Type Explanations Classification Regression
Permutation Feature Importance non-contrastive global
Shap Values non-contrastive local
Surrogate Model contrastive global
Counterfactual Example contrastive local

Description:

  • global: explanation of system functionality (all samples have the same explanation)
  • local: explanation of decision rationale (each sample has its own explanation)
  • contrastive: tracing of decision path (differences to other outcomes are described)
  • non-contrastive: parameter weighting (the feature importance is reported)

Documentation

https://explainy.readthedocs.io

Install explainy

pip install explainy

Usage

📚 A comprehensive example of the explainy API can be found in this Jupyter Notebook

📖 Or in the example section of the documentation

Initialize and train a scikit-learn model:

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)
model.fit(X_train, y_train)

Initialize the PermutationExplanation (or any other explanation) object and pass in the trained model and the to be explained dataset.

Addtionally, define the number of features used in the explanation. This allows you to configure the verbosity of your exaplanation.

Set the index of the sample that should be explained.

from explainy.explanations import PermutationExplanation

number_of_features = 4

explainer = PermutationExplanation(
    X_test, y_test, model, number_of_features
)

Call the explain() method and print the explanation for the sample (in case of a local explanation every sample has a different explanation).

explanation = explainer.explain(sample_index=1)
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).

Use the plot() method to create a feature importance plot of that sample.

explainer.plot()

Permutation Feature Importance

If your prefer, you can also create another type of plot, as for example a boxplot.

explainer.plot(kind='box')

Permutation Feature Importance BoxPlot

Finally, you can also look at the importance values of the features (in form of a pd.DataFrame).

feature_importance = explainer.importance()
print(feature_importance)
  Feature  Importance
0     bmi        0.15
1      s5        0.12
2      bp        0.03
3     age        0.02
4      s2       -0.00
5     sex       -0.00
6      s3       -0.00
7      s1       -0.01
8      s6       -0.01
9      s4       -0.01

Features

  • Algorithms for inspecting black-box machine learning models
  • Support for the machine learning frameworks scikit-learn and xgboost
  • explainy offers a standardized API with three core methods explain(), plot(), importance()

Other Machine Learning Explainability libraries to watch

  • shap: A game theoretic approach to explain the output of any machine learning model
  • eli5: A library for debugging/inspecting machine learning classifiers and explaining their predictions
  • alibi: Algorithms for explaining machine learning models
  • interpret: Fit interpretable models. Explain blackbox machine learning

Source

Molnar, Christoph. "Interpretable machine learning. A Guide for Making Black Box Models Explainable", 2019. https://christophm.github.io/interpretable-ml-book/

Author

Mauro Luzzatto - Maurol

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].