mlflow-explainable
Log explainable ML models (predictor + SHAP explainer) to MLflow as a single
self-contained mlflow.pyfunc artifact. Designed for a multi-model serving
runtime that should not need to know whether the underlying model is a sklearn
estimator, an XGBoost booster, or a custom torch network.
Installation
pip install mlflow-explainable
Quick start
sklearn-style model
import mlflow
from sklearn.ensemble import RandomForestClassifier
from mlflow_explainable import log_explainable_model
model = RandomForestClassifier().fit(X_train, y_train)
with mlflow.start_run():
mlflow.log_metric("accuracy", acc)
log_explainable_model(
model,
X_train,
registered_name="sample-rf-crc",
)
Gradient Boosting (sklearn)
from sklearn.ensemble import GradientBoostingClassifier
from mlflow_explainable import log_explainable_model
model = GradientBoostingClassifier().fit(X_train, y_train)
with mlflow.start_run():
log_explainable_model(model, X_train, registered_name="sample-gb-crc")
XGBoost
import xgboost as xgb
from mlflow_explainable import log_explainable_model
model = xgb.XGBClassifier(eval_metric="logloss").fit(X_train, y_train)
with mlflow.start_run():
log_explainable_model(
model,
X_train,
registered_name="sample-xgboost-crc",
extra_pip_requirements=["xgboost"],
)
Note: as of shap 0.49 the meta-Explainer no longer auto-detects
XGBClassifier. log_explainable_model transparently retries with
model.predict_proba when this happens, so the user-facing API stays the same.
Custom torch model (or any callable wrapper)
from mlflow_explainable import log_explainable_model
wrapper = GCNTabularWrapper(gcn, edge_index, device, feature_names)
with mlflow.start_run():
mlflow.log_metric("accuracy", acc)
log_explainable_model(
wrapper,
X_train,
registered_name="sample-gcn-crc",
explainer_kwargs={"algorithm": "permutation"},
extra_pip_requirements=["torch", "torch_geometric"],
)
The library walks the predictor's object graph, collects source files of any
user-defined classes (skipping stdlib and well-known third-party prefixes),
and packs them into the artifact via MLflow's code_path. The serving runtime
never needs to import those classes from its own codebase.
Loading at serving time
loaded = mlflow.pyfunc.load_model(model_uri)
impl = loaded._model_impl.python_model # ExplainableModel instance
# 1) standard pyfunc predict — returns DataFrame[Y_proba, Y_class]
result = loaded.predict(X)
# 2) SHAP explanation — uniform shape across all explainer types
explanation = impl.shap_explain(X)
# explanation["values"] shape (n, n_features) or (n, n_features, n_classes)
# explanation["base_values"] shape () or (n_classes,) or (n, n_classes)
# explanation["data"] shape (n, n_features)
Why a contract?
mlflow.sklearn.load_model ties the runtime to the sklearn API. Adding a
torch model means another branch, another set of attribute assumptions
(predict_proba, expected_value, ...), and another way for kserve to
break when the SHAP version changes.
mlflow-explainable standardises the runtime-facing surface to two methods —
predict and shap_explain — and pushes all framework-specific glue into the
artifact itself.
License
MIT
Metadata
Release files for mlflow-explainable 1.0.2
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 |
|---|---|---|---|---|
| mlflow_explainable-1.0.2.tar.gz | 16.2 kB | With provenance | Details for mlflow_explainable-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mlflow_explainable-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for mlflow_explainable-1.0.2-py3-none-any.whl |
Total release size: 29.0 kB
Release files / mlflow_explainable-1.0.2.tar.gz
| Download URL | mlflow_explainable-1.0.2.tar.gz |
|---|---|
| Size | 16.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9516344a42fad88240c2062e0ebd2433999a589e299cbbd90508a06ab8792a02
|
|
BLAKE2b-256 checksum How to use checksums |
59db8b26409c5954baec3abae8fe1c565f7d6bb7931ef8e48a7231b86d039a4c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.
Transparency logRelease files / mlflow_explainable-1.0.2-py3-none-any.whl
| Download URL | mlflow_explainable-1.0.2-py3-none-any.whl |
|---|---|
| Size | 12.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
593b831b5cb7280f15ade9c351405c969a158fa6f1bd4bdf02e9835119cb4a63
|
|
BLAKE2b-256 checksum How to use checksums |
158bfd7cc15a24ad978d553e75800f14ab48e1f2178c4eee9bad3cf79cf6035c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.
Transparency logSecurity for mlflow-explainable 1.0.2
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for mlflow_explainable-1.0.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.
Transparency logA 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.