midlearn
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, and second-order interaction effects, minimizing the squared residuals.
- Model Fidelity: Quantifies the quality of the explanation and the complexity of the model 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 is a functional decomposition method that deconstructs a black-box prediction function $f(\mathbf{X})$ into several interpretable components: an intercept $g_\emptyset$, main effects $g_j(X_j)$, and second-order interactions $g_{jk}(X_j, X_k)$, minimizing the squared residuals $\mathbf{E}\left[g_D(\mathbf{X})^2\right]$:
$$ f(\mathbf{X}) = g_\emptyset + \sum_{j} g_j(X_{j}) + \sum_{j < k} g_{jk}(X_{j},;X_{k}) + g_D(\mathbf{X}) $$
To ensure the uniqueness and identifiability of each component, MID imposes centering and probability-weighted minimum-norm constraints on the decomposition.
By approximating a black-box model with this surrogate structure, we can derive a representation that retains the superior predictive power of machine learning models without sacrificing actuarial transparency. Furthermore, it allows us to quantify the "uninterpreted" variance, i.e., the portion of the model's logic that can't be captured by low-order effects, via the residual term $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.
Metadata
Release files for midlearn 0.1.6
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 | |
|---|---|---|---|---|
| midlearn-0.1.6.tar.gz | 24.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| midlearn-0.1.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 49.9 kB
Release files / midlearn-0.1.6.tar.gz
| Download URL | midlearn-0.1.6.tar.gz |
|---|---|
| Size | 24.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2d156999e6113ee09f06f6181132a150051ab7803cb5a70c0f07c726044092d9
|
|
BLAKE2b-256 checksum How to use checksums |
f02c24e857089e2578cc02e8defe85f722454e4f11b71b919ca310592d09f0bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.5
|
Release files / midlearn-0.1.6-py3-none-any.whl
| Download URL | midlearn-0.1.6-py3-none-any.whl |
|---|---|
| Size | 25.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4bd82add32efd1c44bda9a68555c028bff8e90d47b80197c66c0337cc6d841b9
|
|
BLAKE2b-256 checksum How to use checksums |
6e8d62d65719f9da16ebfc34e35b7d7367c381d3ab870dfc2ab0f1bd242f6087
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.5
|
Security for midlearn 0.1.6
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.