Ethical AI (eai)
A comprehensive Python package for ethical AI validation and auditing, designed with a modular structure similar to scikit-learn.
Features
- Bias Detection: Identify and measure bias in AI models across different demographic groups
- Fairness Assessment: Evaluate model fairness using various metrics and statistical tests
- GDPR Compliance: Check for data privacy and consent requirements
- AI Act Compliance: Validate compliance with EU AI Act regulations
- Comprehensive Reporting: Generate detailed audit reports with visualizations
- Multiple Model Support: Works with scikit-learn, TensorFlow, and PyTorch models
Installation
From PyPI (Recommended)
pip install whis-ethical-ai
From Source
git clone https://github.com/whis-19/ethical-ai.git
cd ethical-ai
pip install -e .
Quick Start
Basic Usage
from ethical_ai_validator import EthicalAIValidator
import numpy as np
import pandas as pd
# Create sample data
predictions = np.array([1, 0, 1, 0, 1, 0, 1, 1, 0, 1])
true_labels = np.array([1, 0, 1, 1, 0, 0, 1, 1, 0, 1])
protected_attributes = {
'gender': ['male', 'female', 'male', 'female', 'male', 'female', 'male', 'female', 'male', 'female'],
'race': ['white', 'black', 'white', 'black', 'white', 'black', 'white', 'black', 'white', 'black']
}
# Initialize validator
validator = EthicalAIValidator()
# Detect bias
bias_report = validator.audit_bias(predictions, true_labels, protected_attributes)
print("Bias Report:")
print(bias_report)
# Calculate fairness metrics
fairness_metrics = validator.calculate_fairness_metrics(predictions, protected_attributes)
print("Fairness Metrics:")
print(fairness_metrics)
Advanced Usage
# Generate compliance report
metadata = {'model_name': 'RandomForest', 'version': '1.0'}
audit_criteria = {'bias_threshold': 0.1, 'fairness_threshold': 0.8}
report_path = validator.generate_compliance_report(metadata, audit_criteria)
# Real-time monitoring
predictions_stream = [
np.random.choice([0, 1], size=1000),
np.random.choice([0, 1], size=1000)
]
alerts = validator.monitor_realtime(predictions_stream)
# Suggest mitigations
mitigations = validator.suggest_mitigations(bias_report)
print("Mitigation Suggestions:")
print(mitigations)
Using Convenience Functions
from ethical_ai_validator import (
audit_bias, calculate_fairness_metrics, generate_compliance_report,
monitor_realtime, suggest_mitigations
)
# Direct function calls
bias_report = audit_bias(predictions, true_labels, protected_attributes)
fairness_metrics = calculate_fairness_metrics(predictions, protected_attributes)
report_path = generate_compliance_report(metadata, audit_criteria)
alerts = monitor_realtime(predictions_stream)
mitigations = suggest_mitigations(bias_report)
Development Setup
Prerequisites
- Python 2.7 or higher
- Git
- pip
Step-by-Step Setup
- Clone the repository
git clone https://github.com/whis-19/ethical-ai.git
cd ethical-ai
2. **Create a virtual environment**
```bash
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt pip install -e .[dev]
-
Run tests
pytest
-
Check code coverage
pytest --cov=ethical_ai_validator --cov-report=html
VS Code Setup
-
Install recommended extensions:
- Python (ms-python.python)
- Pylance (ms-python.vscode-pylance)
- Python Test Explorer (littlefoxteam.vscode-python-test-adapter)
-
Configure settings in
.vscode/settings.json(already included)
Project Structure
ethical-ai/
├── src/
│ └── ethical_ai_validator/
│ ├── __init__.py
│ ├── core/
│ ├── validators/
│ ├── metrics/
│ └── reporting/
├── tests/
├── docs/
├── requirements.txt
├── pyproject.toml
├── README.md
└── SETUP.md
Testing
Run the test suite:
# Run all tests
pytest
# Run with coverage
pytest --cov=ethical_ai_validator --cov-report=html
# Run specific test categories
pytest -m unit
pytest -m integration
pytest -m "not slow"
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Code Style
This project uses:
- Black for code formatting
- Flake8 for linting
- MyPy for type checking
- Pre-commit hooks for automated checks
Run pre-commit hooks:
pre-commit install
pre-commit run --all-files
Documentation
License
This project is licensed under the MIT License - see the LICENSE file for complete details.
License Summary
✅ Permitted:
- Commercial use
- Modification and distribution
- Private and public use
- Patent use
❌ Limitations:
- No warranty provided
- No liability for damages
📋 Requirements:
- Include copyright notice
- Include license text
- State any modifications
License Compatibility
The MIT License is compatible with:
- GPL (v2 and v3)
- Apache License 2.0
- BSD Licenses
- Most other open-source licenses
This makes it suitable for use in both open-source and commercial projects.
Third-Party Dependencies
All dependencies are BSD-3-Clause licensed and compatible with MIT:
- numpy, pandas, scikit-learn, reportlab
For detailed license information, see the LICENSE file.
Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: muhammadabdullahinbox@gmail.com
Acknowledgments
- Inspired by the need for ethical AI development
- Built with support from the open-source community
- Special thanks to contributors and maintainers (WHIS-19)
Metadata
Release files for whis-ethical-ai 1.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| whis_ethical_ai-1.3.0.tar.gz | 59.8 kB | Without provenance | Details for whis_ethical_ai-1.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| whis_ethical_ai-1.3.0-py3-none-any.whl | Python 3 | none | any | Details for whis_ethical_ai-1.3.0-py3-none-any.whl |
Total release size: 93.3 kB
Release files / whis_ethical_ai-1.3.0.tar.gz
| Download URL | whis_ethical_ai-1.3.0.tar.gz |
|---|---|
| Size | 59.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aeec3517135cf295ba83741f58fe4b4549cc987824af341eb53199d91cb43bd7
|
|
BLAKE2b-256 checksum How to use checksums |
35b033a7fb3326721dc3e0f5064642d6e24e50cced067c47ce3820eebc5bca85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / whis_ethical_ai-1.3.0-py3-none-any.whl
| Download URL | whis_ethical_ai-1.3.0-py3-none-any.whl |
|---|---|
| Size | 33.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0f496053bbd31e195ea1146d53a083b2fed44c37b5b9f417bb57a8fe7b97a13c
|
|
BLAKE2b-256 checksum How to use checksums |
8a260b7fb9663942f6f06b96f5830d0a9ea53744f267a6ff51d9ba26069e0a49
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Security for whis-ethical-ai 1.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.