Skip to main content

XAI explainers to Machine Learning Models

Project description

Logic Explain Machine Learning - LEML

logic-explain-ml 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 logic-explain-ml

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

logicexplainml-0.1.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

logicexplainml-0.1.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file logicexplainml-0.1.0.tar.gz.

File metadata

  • Download URL: logicexplainml-0.1.0.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

Hashes for logicexplainml-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d615481709b5219b7b41f79d2a5946a9535be0089087d24e5793309c820055a8
MD5 631bec42639cfce6e41872db43f6e10c
BLAKE2b-256 221d5b498f5abdfaec1d5ae02f7b89708abe8fffd4ee23a7a0f0949d21e5d9e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for logicexplainml-0.1.0.tar.gz:

Publisher: python-publish.yml on LogicExplainML-LEML/LogicExplainML

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file logicexplainml-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: logicexplainml-0.1.0-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

Hashes for logicexplainml-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b8bbc68313c0763802a03050d5971b4afbc5bbb3fa86d5c8363ecc3638d7432c
MD5 aa9828988468c8b7df86b8ec00cc1c06
BLAKE2b-256 ff7832206a8d028a2aa15c1d1b0e201f2b05be7ec561a99957ce23f3eb561478

See more details on using hashes here.

Provenance

The following attestation bundles were made for logicexplainml-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on LogicExplainML-LEML/LogicExplainML

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page