Skip to main content

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


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.1.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.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

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

Hashes for logicexplainml-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0403950bc5263060834293fdf6a8d72de2de7755ae01e19b9fcf4bd6cfc2c7f1
MD5 b4ca0021044e0bbf1b6c0f15d911c525
BLAKE2b-256 e6110e38bc5007694da2abc805397f8ee9489aace98f9d125ab17bc3c9806255

See more details on using hashes here.

Provenance

The following attestation bundles were made for logicexplainml-0.1.1.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.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

Hashes for logicexplainml-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a28bc46b32a50138957c90b206f6e8fc38af210fc264a2c4c37ed277a306f40f
MD5 481f3a70e15248d431bc59725fa9c90b
BLAKE2b-256 1fbc195c6157b17c5cae83d6d5e8f208a07dca24626009ac84f4861e99553f4e

See more details on using hashes here.

Provenance

The following attestation bundles were made for logicexplainml-0.1.1-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