Skip to main content

Python Wrapper of the 'midr' R package to interpret black-box models.

Project description

midlearn

PyPI version License: MIT

midlearn is a rpy2-based Python wrapper for the midr R package. It provides a model-agnostic framework for interpreting black-box models using a scikit-learn compatible API.

The core objective of midlearn is to create a globally interpretable surrogate model through Maximum Interpretation Decomposition (MID). This technique finds an optimal additive approximation of any black-box model (e.g., GBMs, Neural Networks) by minimizing the squared error between the original predictions and the surrogate's components.

Main Features

  • Scikit-learn Compatible API: Fits seamlessly into existing workflows with familiar .fit() and .predict() methods.
  • Functional Decomposition: Deconstructs model predictions into an intercept, main effects $g_j(X_j)$, and interaction effects $g_{jk}(X_j, X_k)$.
  • Model Fidelity: Quantifies the quality of the explanation using the Uninterpreted Variation Ratio.
  • Seamless Visualization: Built-in support for plotnine-based interfaces to generate feature importance, dependence plots, and additive breakdowns.

Installation

midlearn requires an R installation on your system with the midr package.

1. Install R Package

From CRAN:

install.packages('midr')

Or from GitHub:

pak::pak("ryo-asashi/midr")

2. Install Python package

From PyPI:

pip install midlearn

Or from GitHub:

pip install git+https://github.com/ryo-asashi/midlearn.git

Theoretical Foundation

MID approximates a complex prediction function $f(\mathbf{x})$ as a sum of interpretable functions: $$ f(\mathbf{x}) \approx g_\emptyset + \sum_{j} g_j(X_{j}) + \sum_{j < k} g_{jk}(X_{j}, X_{k}) + \dots + g_D(\mathbf{x}) $$

The theoretical foundations of MID are described in Iwasawa & Matsumori (2026) [Forthcoming], and the software implementation is detailed in Asashiba et al. (2025).

License

midlearn is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

midlearn-0.1.3.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

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

midlearn-0.1.3-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file midlearn-0.1.3.tar.gz.

File metadata

  • Download URL: midlearn-0.1.3.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for midlearn-0.1.3.tar.gz
Algorithm Hash digest
SHA256 7c55c579d520a11eebc7fbf7e7454f31436af06f8c8fce38bb6743d7a0670ea2
MD5 1339b6c41403cfb44e59b82bad94c1b5
BLAKE2b-256 f47bcfcc97a7f99ca935c83ccf1509b61d9522c40ea61073b439546d37c96cb9

See more details on using hashes here.

File details

Details for the file midlearn-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: midlearn-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 20.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for midlearn-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 dead64a69b125ae9f71f2216aa112882e4c5743a263c3403668b23518f22ec67
MD5 9e1a660f0357a478951fbeb286fd2ce4
BLAKE2b-256 2ace4555b7f39a0197de9065f6a38e9147a51c1f831d3135e58535ec44577066

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 Pingdom Monitoring Sentry Error logging StatusPage Status page