XAI explainers to Machine Learning Models
Project description
Logic Explain Machine Learning - LEML
LogicExplainML is a Python library for explaining predictions of Machine Learning models.
It provides an easy-to-use interface to inspect feature importance and generate human-readable explanations for individual predictions.
By this date it only explains XGBoost models.
Installation
You can install the package via pip:
pip install LogicExplainML
Features
- Fit an explainer for XGBoost models.
- Compute feature importance.
- Generate interpretable explanations for individual predictions.
Usage
Here's a simple example using the Iris dataset and XGBClassifier:
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from xgboost import XGBClassifier
import pandas as pd
from logic_explain_ml.xgboost import XGBoostExplainer
# Load the dataset
iris = load_iris()
X = pd.DataFrame(iris.data, columns=iris.feature_names)
y = iris.target
# Convert to binary classification
y[y == 2] = 0
# Split the data
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=101
)
# Train an XGBoost classifier
xgbc = XGBClassifier(n_estimators=100, max_depth=3, learning_rate=0.1)
xgbc.fit(X_train, y_train)
# Make predictions
preds = xgbc.predict(X_test)
print(preds)
# Initialize and fit the explainer
explainer = XGBoostExplainer(xgbc, X)
explainer.fit()
# Inspect feature importance
print(xgbc.feature_importances_, xgbc.feature_names_in_)
# Explain a single sample
sample = [5.5, 4.2, 1.4, 0.2]
exp = explainer.explain(sample, reorder="asc")
print(exp)
Example Output
init: -0.73
prob: -2.96
tree prob: 4.65
[petal length (cm) == 1.4]
License
This project is licensed under the MIT License.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file logicexplainml-0.1.1.tar.gz.
File metadata
- Download URL: logicexplainml-0.1.1.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0403950bc5263060834293fdf6a8d72de2de7755ae01e19b9fcf4bd6cfc2c7f1
|
|
| MD5 |
b4ca0021044e0bbf1b6c0f15d911c525
|
|
| BLAKE2b-256 |
e6110e38bc5007694da2abc805397f8ee9489aace98f9d125ab17bc3c9806255
|
Provenance
The following attestation bundles were made for logicexplainml-0.1.1.tar.gz:
Publisher:
python-publish.yml on LogicExplainML-LEML/LogicExplainML
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
logicexplainml-0.1.1.tar.gz -
Subject digest:
0403950bc5263060834293fdf6a8d72de2de7755ae01e19b9fcf4bd6cfc2c7f1 - Sigstore transparency entry: 449730522
- Sigstore integration time:
-
Permalink:
LogicExplainML-LEML/LogicExplainML@b2293b8702a376a9e99cca1f2b4c23d0a3063500 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/LogicExplainML-LEML
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@b2293b8702a376a9e99cca1f2b4c23d0a3063500 -
Trigger Event:
release
-
Statement type:
File details
Details for the file logicexplainml-0.1.1-py3-none-any.whl.
File metadata
- Download URL: logicexplainml-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a28bc46b32a50138957c90b206f6e8fc38af210fc264a2c4c37ed277a306f40f
|
|
| MD5 |
481f3a70e15248d431bc59725fa9c90b
|
|
| BLAKE2b-256 |
1fbc195c6157b17c5cae83d6d5e8f208a07dca24626009ac84f4861e99553f4e
|
Provenance
The following attestation bundles were made for logicexplainml-0.1.1-py3-none-any.whl:
Publisher:
python-publish.yml on LogicExplainML-LEML/LogicExplainML
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
logicexplainml-0.1.1-py3-none-any.whl -
Subject digest:
a28bc46b32a50138957c90b206f6e8fc38af210fc264a2c4c37ed277a306f40f - Sigstore transparency entry: 449730539
- Sigstore integration time:
-
Permalink:
LogicExplainML-LEML/LogicExplainML@b2293b8702a376a9e99cca1f2b4c23d0a3063500 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/LogicExplainML-LEML
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@b2293b8702a376a9e99cca1f2b4c23d0a3063500 -
Trigger Event:
release
-
Statement type: