MachineLens is a XAI Python tool for automated model diagnostics and explainability post training. It is specifically designed to work seamlessly with the scikit-learn ecosystem, streamlining the evaluation of machine learning models through comprehensive reports.
It provides a high-level interface to generate diagnostics for classification and regression tasks, supporting any estimator that follows the scikit-learn API.
Documentation: https://vazfabricio.github.io/MachineLens/
Source code: https://github.com/VazFabricio/MachineLens
Issue tracker: https://github.com/VazFabricio/MachineLens/issues
Installation
Dependencies
MachineLens requires:
Python (>= 3.11)
Scikit-learn (>= 1.7.2)
NumPy (>= 2.2.6)
Pandas (>= 2.3.3)
Plotly (>= 6.3.1)
Statsmodels (>= 0.14.6)
SciPy (>= 1.11.0)
SHAP (>= 0.49.1)
User installation
You can install MachineLens using pip:
pip install machinelens
For a faster installation, you can use uv:
uv pip install machinelens
Quick Start
Classification model
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
import pandas as pd
from machinelens import ModelInterface, ModelAnalyzer, DiagnosticPlotter
# 1. Prepare data and train a model
X, y = make_classification(n_samples=1000, random_state=42)
X_df = pd.DataFrame(X, columns=[f"feature_{i}" for i in range(X.shape[1])])
X_train, X_test, y_train, y_test = train_test_split(X_df, y, test_size=0.2)
model = RandomForestClassifier(random_state=42).fit(X_train, y_train)
# 2. Wrap the model
interface = ModelInterface(model, X_train, X_test, y_train, y_test)
# 3. Run diagnostics
results = ModelAnalyzer(interface).analyze()
# 4. Visualise
plotter = DiagnosticPlotter(results)
plotter.plot_metrics().show()
plotter.plot_roc_curve().show()
plotter.plot_shap_beeswarm().show()
Regression model
from sklearn.ensemble import RandomForestRegressor
from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
import pandas as pd
from machinelens import ModelInterface, ModelAnalyzer, DiagnosticPlotter
X, y = make_regression(n_samples=500, n_features=20, noise=15.0, random_state=42)
X_df = pd.DataFrame(X, columns=[f"Feature_{i+1}" for i in range(X.shape[1])])
X_train, X_test, y_train, y_test = train_test_split(X_df, y, test_size=0.2, random_state=42)
model = RandomForestRegressor(n_estimators=50, random_state=42).fit(X_train, y_train)
interface = ModelInterface(model, X_train, X_test, y_train, y_test)
results = ModelAnalyzer(interface).analyze()
plotter = DiagnosticPlotter(results)
plotter.plot_metrics().show()
plotter.plot_residuals().show()
plotter.plot_shap_beeswarm().show()
Development
We welcome contributions! MachineLens is built with modern Python tooling to ensure code quality and ease of development.
Setting up the environment
The project uses uv for dependency management:
Clone the repository:
git clone https://github.com/VazFabricio/MachineLens.git cd MachineLens
Sync the dependencies and create a virtual environment:
uv sync
This will automatically install all main dependencies and development tools like pytest, ruff, and mypy.
Code Quality
We use ruff for linting and formatting. Before submitting code, please ensure it follows our standards:
Linting & Formatting: Run ruff check and ruff format.
Type Checking: Run mypy src.
Pre-commit: Install the hooks with:
pre-commit install
Testing
Run the test suite from the root directory:
pytest
The test suite includes coverage reports by default.
Help and Support
Communication
GitHub Discussions: https://github.com/VazFabricio/MachineLens/discussions
License
MachineLens is distributed under the BSD 3-Clause License. See LICENSE for more information.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file machinelens-0.1.0.tar.gz.
File metadata
- Download URL: machinelens-0.1.0.tar.gz
- Upload date:
- Size: 368.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd9aeef3127306d1aff416557723f178e3958f578e2e7206f3786539676292d0
|
|
| MD5 |
74dabf61c725622be33c04c54b05e0fc
|
|
| BLAKE2b-256 |
a92d8bd5cb5e657af1ed9bcfc5c2398e8810ebc9179c1cc7a4a7c1f22a63f775
|
File details
Details for the file machinelens-0.1.0-py3-none-any.whl.
File metadata
- Download URL: machinelens-0.1.0-py3-none-any.whl
- Upload date:
- Size: 40.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3fa77baf1905f02f539ac33558ca663763b639994a7bf6599a21696fff5fde22
|
|
| MD5 |
60932d8e17b75530ce8fecebc91330b1
|
|
| BLAKE2b-256 |
51230121072c965d25c7d82d3c473cc4ac37ded50e362fd5f27ca437ac811918
|