Skip to main content

XplainML: Empowering Transparent and Responsible AI

GitHub stars GitHub license

Welcome to XplainML – your ultimate toolkit for unlocking the power of transparent and responsible AI! Designed and developed by Deependra Verma, XplainML empowers data scientists, machine learning engineers, and AI practitioners to understand, interpret, and trust their models with ease.

Introduction

XplainML is an open-source Python package designed to provide transparent and responsible AI capabilities to users. With XplainML, you can easily interpret your AI models, detect and mitigate bias, ensure fairness, and promote ethical AI practices.

Features

Explainable AI (XAI) Made Easy

Unravel the mysteries of your AI models with intuitive explanations using state-of-the-art techniques like SHAP and LIME.

Responsible AI Integration

Detect and mitigate bias, ensure fairness, and promote ethical AI practices with built-in fairness metrics and bias mitigation algorithms.

Installation

To install XplainML, simply run:

pip install XplainML

Usage

Explainable AI (XAI)

SHAP Explanations

# Import the necessary libraries
import shap
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier

# Load the Iris dataset
iris = load_iris()
X, y = iris.data, iris.target

# Train a random forest classifier
model = RandomForestClassifier(n_estimators=100, random_state=42)
model.fit(X, y)

# Initialize the SHAP explainer
explainer = shap.Explainer(model)

# Generate SHAP explanations for a sample instance
shap_values = explainer(X[:1])

# Visualize the SHAP explanations
shap.plots.waterfall(shap_values[0])

LIME Explanations

# Import the necessary libraries
import lime
import lime.lime_tabular
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier

# Load the Iris dataset
iris = load_iris()
X, y = iris.data, iris.target

# Train a random forest classifier
model = RandomForestClassifier(n_estimators=100, random_state=42)
model.fit(X, y)

# Initialize the LIME explainer
explainer = lime.lime_tabular.LimeTabularExplainer(X, feature_names=iris.feature_names, class_names=iris.target_names)

# Generate LIME explanations for a sample instance
explanation = explainer.explain_instance(X[0], model.predict_proba)

# Visualize the LIME explanations
explanation.show_in_notebook()

Responsible AI Integration

Bias Detection

# Import the necessary libraries
from aif360.datasets import GermanDataset
from aif360.metrics import BinaryLabelDatasetMetric

# Load the German credit dataset
dataset = GermanDataset()
privileged_group = [{'sex': 1}]
unprivileged_group = [{'sex': 0}]

# Compute metrics for bias detection
metric = BinaryLabelDatasetMetric(dataset, unprivileged_group=unprivileged_group, privileged_group=privileged_group)
print("Mean Difference: ", metric.mean_difference())
print("Disparate Impact: ", metric.disparate_impact())

Bias Mitigation

# Import the necessary libraries
from aif360.algorithms.preprocessing import Reweighing

# Apply bias mitigation using Reweighing
biased_dataset = dataset.convert_to_dataframe()[0]
rw = Reweighing(unprivileged_groups=unprivileged_group, privileged_groups=privileged_group)
biased_dataset = rw.fit_transform(biased_dataset)

# Verify bias mitigation results
metric_biased = BinaryLabelDatasetMetric(biased_dataset, unprivileged_group, privileged_group)
print("Mean Difference after mitigation: ", metric_biased.mean_difference())
print("Disparate Impact after mitigation: ", metric_biased.disparate_impact())

Contributing

We welcome contributions from the community! Whether it's fixing bugs, adding new features, or improving documentation, your contributions help make XplainML better for everyone. Check out our Contributing Guidelines to get started.

License

XplainML is licensed under the MIT License. See the LICENSE file for details.

About the Author

Deependra Verma
Data Scientist
Email | LinkedIn | GitHub | Portfolio

Release files for XplainML 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for XplainML 0.0.1
File Size Uploaded
XplainML-0.0.1.tar.gz 6.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for XplainML 0.0.1
File Interpreter ABI Platform
XplainML-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 11.5 kB

Release files / XplainML-0.0.1.tar.gz

Download URL XplainML-0.0.1.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
778d5c08e775914f51c9c85bb4870d8d7990c5d8d461935a1168f0cf843ec986
BLAKE2b-256 checksum
How to use checksums
68f1846fa76a58db11c81e8e5f03d60cc3ea6c9ca4409fde96a6e4cce5ce3499
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.19

Release files / XplainML-0.0.1-py3-none-any.whl

Download URL XplainML-0.0.1-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eb47aff99b5e3ac0ce196f1a97d2968982081db1f0539757b94ace8f13fc55ee
BLAKE2b-256 checksum
How to use checksums
33e636d66d7ef909a6ed24dc38c7c5d5a364983c6b0b8502e6422be55504d1e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.19

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page