Skip to main content

ExplainableAI

PyPI version License: MIT Python Versions Downloads GitHub stars

ExplainableAI is a powerful Python package that combines state-of-the-art machine learning techniques with advanced explainable AI methods and LLM-powered explanations.

Table of Contents

Features

  • Automated Exploratory Data Analysis (EDA): Gain quick insights into your dataset.
  • Model Performance Evaluation: Comprehensive metrics for model assessment.
  • Feature Importance Analysis: Understand which features drive your model's decisions.
  • SHAP (SHapley Additive exPlanations) Integration: Deep insights into model behavior.
  • Interactive Visualizations: Explore model insights through intuitive charts and graphs.
  • LLM-Powered Explanations: Get human-readable explanations for model results and individual predictions.
  • Automated Report Generation: Create professional PDF reports with a single command.
  • Multi-Model Support: Compare and analyze multiple ML models simultaneously.
  • Easy-to-Use Interface: Simple API for model fitting, analysis, and prediction.

Installation

Install ExplainableAI using pip:

pip install explainableai

Quick Start

from explainableai import XAIWrapper
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier

# Load sample dataset
X, y = load_iris(return_X_y=True, as_frame=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Initialize XAIWrapper
xai = XAIWrapper()

# Fit and analyze model
model = RandomForestClassifier(n_estimators=100, random_state=42)
xai.fit(model, X_train, y_train)
results = xai.analyze(X_test, y_test)

# Print LLM explanation
print(results['llm_explanation'])

# Generate report
xai.generate_report('iris_analysis.pdf')

Usage Examples

Multi-Model Comparison

from explainableai import XAIWrapper
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import LogisticRegression
from xgboost import XGBClassifier
import pandas as pd

# Load your dataset
df = pd.read_csv('your_dataset.csv')
X = df.drop(columns=['target_column'])
y = df['target_column']

# Create models
models = {
    'Random Forest': RandomForestClassifier(n_estimators=100, random_state=42),
    'Logistic Regression': LogisticRegression(max_iter=1000),
    'XGBoost': XGBClassifier(n_estimators=100, random_state=42)
}

# Initialize XAIWrapper
xai = XAIWrapper()

# Fit and analyze models
xai.fit(models, X, y)
results = xai.analyze()

# Print LLM explanation of results
print(results['llm_explanation'])

# Generate a comprehensive report
xai.generate_report('multi_model_comparison.pdf')

Explaining Individual Predictions

# ... (after fitting the model)

# Make a prediction with explanation
new_data = {...}  # Dictionary of feature values
prediction, probabilities, explanation = xai.explain_prediction(new_data)

print(f"Prediction: {prediction}")
print(f"Probabilities: {probabilities}")
print(f"Explanation: {explanation}")

Environment Variables

To use the LLM-powered explanations, you need to set up the following environment variable:

Add this to your .env file:

GEMINI_API_KEY=your_api_key_here

API Reference

For detailed API documentation, please refer to our API Reference.

Running Locally

To run ExplainableAI locally:

  1. Clone the repository:

    git clone https://github.com/ombhojane/explainableai.git
    cd explainableai
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Set up your environment variables (see Environment Variables).

  4. Run the example script:

    python main.py [dataset] [target_column]
    

Contributing

We welcome contributions to ExplainableAI! Please see our Contributing Guidelines for more information on how to get started.

Credits

Explainable AI was created by Om Bhojane. Special thanks to the following contributors for their support.

Acknowledgements

ExplainableAI builds upon several open-source libraries, including:

We are grateful to the maintainers and contributors of these projects.

License

ExplainableAI is released under the MIT License.

Metadata

Release files for explainableai 0.10

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

Source distribution (sdist)

Source distribution for explainableai 0.10
File Size Uploaded
explainableai-0.10.tar.gz 24.8 kB Details

Built distribution (wheel)

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

Total release size: 51.4 kB

Release files / explainableai-0.10.tar.gz

Download URL explainableai-0.10.tar.gz
Size 24.8 kB
Tags Source
SHA-256 checksum
How to use checksums
4ba5c2c0a38c6ed8cdc5cefe1df12fe76d199b66bf5a3eb67aca99471c6958d2
BLAKE2b-256 checksum
How to use checksums
60236925fa7b397bbfeb74157403d87c082ec5575d71e174be882481f19acc5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.6

Release files / explainableai-0.10-py3-none-any.whl

Download URL explainableai-0.10-py3-none-any.whl
Size 26.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
15fba6a0a1b0d706d4ddc6c545e827151f7141060d9a91e8a13162765e176845
BLAKE2b-256 checksum
How to use checksums
171422e0874d71483d7e1199c815e36e7382b2a6aef2124ad2d40a4eaad65718
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.6

Release history Release notifications | RSS feed

This release

0.10 This release

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1

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