Skip to main content

CI Status Code style: Ruff License: BSD 3-Clause Python 3.11 | 3.12 | 3.13

MachineLens Logo

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.

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:

  1. Clone the repository:

    git clone https://github.com/VazFabricio/MachineLens.git
    cd MachineLens
  2. 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

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

machinelens-0.1.1.tar.gz (369.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

machinelens-0.1.1-py3-none-any.whl (41.1 kB view details)

Uploaded Python 3

File details

Details for the file machinelens-0.1.1.tar.gz.

File metadata

  • Download URL: machinelens-0.1.1.tar.gz
  • Upload date:
  • Size: 369.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for machinelens-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e4b2ab1d79e279b0a9c8a884fc37951ff61a13bb2132dd035cca28795b4ca4c8
MD5 0f321670788fd82bd454f9ec9de490da
BLAKE2b-256 6849bc9dccdfae540ec48eca60da7dccdfd0c0493d345ec0343092c17ed9839b

See more details on using hashes here.

File details

Details for the file machinelens-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: machinelens-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 41.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for machinelens-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fa1919769e602e316d88edb1a20d713ae223298017276276eadb6abc19f86411
MD5 e2e2f9926d9dcd0dc8fd4fd1fb8044ee
BLAKE2b-256 a4a3f6bdb8400b2dcccd52a14886c8831e4e5dec086a77a99504cae21f2ead07

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page