Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
shravya312 committed Oct 20, 2024
2 parents a243669 + adbf086 commit 7df26a6
Show file tree
Hide file tree
Showing 15 changed files with 997 additions and 168 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/auto-comment-on-close.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Comment on Issue Close

on:
issues:
types: [closed]

jobs:
greet-on-close:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Greet User
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue = context.payload.issue;
const issueCreator = issue.user.login;
const issueNumber = issue.number;
const greetingMessage = `Hello @${issueCreator}! Your issue #${issueNumber} has been closed. Thank you for your contribution!🚀`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: greetingMessage
});
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ env
.env
build
dist
*.pyc
*.pyc
venv/
224 changes: 128 additions & 96 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,189 +1,221 @@
# ExplainableAI
# ExplainableAI 🚀

[![PyPI version](https://img.shields.io/pypi/v/explainableai.svg)](https://pypi.org/project/explainableai/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Python Versions](https://img.shields.io/pypi/pyversions/explainableai.svg)](https://pypi.org/project/explainableai/)
[![Downloads](https://pepy.tech/badge/explainableai)](https://pepy.tech/project/explainableai)
[![GitHub stars](https://img.shields.io/github/stars/ombhojane/explainableai.svg)](https://github.com/ombhojane/explainableai/stargazers)

ExplainableAI is a powerful Python package that combines state-of-the-art machine learning techniques with advanced explainable AI methods and LLM-powered explanations.
**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](#features)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Usage Examples](#usage-examples)
- [Environment Variables](#environment-variables)
- [API Reference](#api-reference)
- [Running Locally](#running-locally)
- [Contributing](#contributing)
- [Acknowledgements](#acknowledgements)
- [License](#license)
## 🌟 Key Features

## Features
| Feature | Description |
|--------------------------------------|------------------------------------------------------------------------------------------------------|
| 📊 **Automated 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 Integration** | Deep insights into model behavior using SHAP (SHapley Additive exPlanations). |
| 📊 **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. |

- **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:
## 🚀 Quick Start

```bash
pip install explainableai
```
# ExplainableAI Example: Iris Dataset with Random Forest

## 📝 Code Overview

## Quick Start
This example demonstrates how to use the `ExplainableAI` package to fit a Random Forest model on the Iris dataset, analyze model behavior, and generate an LLM-powered explanation and PDF report.

```python
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
# Load 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
# Initialize and fit model
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
# Analyze and explain results
results = xai.analyze(X_test, y_test)
print(results['llm_explanation'])

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

## Usage Examples
## 🛠️ Installation & Setup

Install ExplainableAI via pip:

```bash
pip install explainableai
```
To use LLM-powered explanations, you need to set up the following environment variable:

```makefile
GEMINI_API_KEY=your_api_key_here
```
# 🖥️ Usage Examples

## Multimodal Example Usage for ExplainableAI

To create a **multimodal example usage** for your ExplainableAI project, we can incorporate various modes of interaction and output that enhance user engagement and understanding. This includes:

1. **Text Explanations**: Providing clear and concise explanations for model predictions.
2. **Dynamic Visualizations**: Integrating libraries to create real-time visualizations of model performance metrics and feature importance.
3. **Interactive Elements**: Utilizing libraries to create an interactive interface where users can input data for real-time predictions and view explanations.

### Implementation Steps

### Multi-Model Comparison
### Example Code

Here’s a sample implementation that incorporates these multimodal elements:

```python
from explainableai import XAIWrapper
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import LogisticRegression
from xgboost import XGBClassifier
import pandas as pd
import streamlit as st

# Load your dataset
# Load your dataset (Replace 'your_dataset.csv' with the actual file)
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 the model
model = RandomForestClassifier(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')
xai.fit(model, X, y)

# Streamlit UI
st.title("Explainable AI Model Prediction")
st.write("This application provides explanations for model predictions and visualizations.")

# User Input for Prediction
user_input = {}
for feature in X.columns:
user_input[feature] = st.number_input(feature, value=0.0)

# Make prediction
if st.button("Predict"):
new_data = pd.DataFrame(user_input, index=[0])
prediction, probabilities, explanation = xai.explain_prediction(new_data)

st.write(f"**Prediction:** {prediction}")
st.write(f"**Probabilities:** {probabilities}")
st.write(f"**Explanation:** {explanation}")

# Dynamic Visualization
st.subheader("Feature Importance")
st.pyplot(xai.plot_feature_importance(model))

st.subheader("SHAP Values")
st.pyplot(xai.plot_shap_values(model))

# Generate report button
if st.button("Generate Report"):
xai.generate_report('model_analysis_report.pdf')
st.write("Report generated!")
```

### Explaining Individual Predictions
### 🤖 Explaining Individual Predictions

```python
# ... (after fitting the model)
# After fitting the model

# New data to be explained
new_data = {'feature_1': value1, 'feature_2': value2, ...} # Dictionary of feature values

# 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}")
```
## 📊 Feature Overview

## Environment Variables

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

- `GEMINI_API_KEY`: Your [Google Gemini API key](https://ai.google.dev/gemini-api/docs/api-key)

Add this to your `.env` file:

```
GEMINI_API_KEY=your_api_key_here
```

## API Reference
| Module | Description |
|-----------------------|-------------------------------------------------------------------------------------------------|
| `explore()` | Automated exploratory data analysis (EDA) to uncover hidden insights. |
| `fit()` | Train and analyze models with a simple API. Supports multiple models. |
| `analyze()` | Evaluate model performance with SHAP and LLM-based explanations. |
| `explain_prediction()` | Explain individual predictions in plain English using LLMs. |
| `generate_report()` | Create professional PDF reports with visuals, explanations, and analysis. |

For detailed API documentation, please refer to our [API Reference](https://pypi.org/project/explainableai/).
---

## Running Locally
## 🌍 Running Locally

To run ExplainableAI locally:

1. Clone the repository:
1. **Clone the repository**:

```bash
git clone https://github.com/ombhojane/explainableai.git
cd explainableai
```
2.**Install Dependencies**:

2. Install dependencies:
To install the required dependencies, run the following command:

```bash
pip install -r requirements.txt
```
```bash
pip install -r requirements.txt
```
3.**Set up your environment variables**:

3. Set up your environment variables (see [Environment Variables](#environment-variables)).
Add your `GEMINI_API_KEY` to the `.env` file.

4. Run the example script:
```bash
python main.py [dataset] [target_column]
```

## Contributing

We welcome contributions to ExplainableAI! Please see our [Contributing Guidelines](CONTRIBUTING.md) for more information on how to get started.
GEMINI_API_KEY=your_api_key_here
```
---

## Credits
### 🤝 Contributing
We welcome contributions to ExplainableAI! Please check out our [Contributing Guidelines](CONTRIBUTING.md) to get started. Contributions are what make the open-source community an incredible place to learn, inspire, and create.

Explainable AI was created by [Om Bhojane](https://github.com/ombhojane). Special thanks to the following contributors for their support.
---

<p align="start">
<a href="https://github.com/ombhojane/explainableai/graphs/contributors">
<img src="https://contrib.rocks/image?repo=ombhojane/explainableai"/>
</a>
</p>
### 📄 License
ExplainableAI is licensed under the [MIT License](https://opensource.org/licenses/MIT).

## Acknowledgements
---

### 🙌 Acknowledgements
ExplainableAI builds upon several open-source libraries, including:

- [scikit-learn](https://scikit-learn.org/)
- [SHAP](https://github.com/slundberg/shap)
- [Matplotlib](https://matplotlib.org/)
- [XGBoost](https://xgboost.readthedocs.io/)

We are grateful to the maintainers and contributors of these projects.
Special thanks to all the contributors who have made this project possible!

<p align="center">
<a href="https://github.com/ombhojane/explainableai/graphs/contributors">
<img src="https://contrib.rocks/image?repo=ombhojane/explainableai" alt="Contributors"/>
</a>
</p>



## License

ExplainableAI is released under the [MIT License](LICENSE).
Loading

0 comments on commit 7df26a6

Please sign in to comment.