lime_ndt
lime_ndt is a Python library that introduces an enhanced version of the LIME technique for model explainability, leveraging Neural Decision Trees (NDTs) for improved local and global interpretability of machine learning models.
Installation
pip install lime_ndt
Quick Start (Classification)
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from lime_ndt import LimeNdtExplainer
# Load data and train a model
iris = load_iris()
X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, random_state=42)
rf = RandomForestClassifier(random_state=42).fit(X_train, y_train)
# Explain a prediction (NDT surrogate is used by default)
explainer = LimeNdtExplainer(X_train, feature_names=iris.feature_names,
class_names=iris.target_names.tolist(), mode='classification')
exp = explainer.explain_instance(X_test[0], rf.predict_proba)
# Visualize
exp.as_pyplot_figure()
Regression Example
from sklearn.datasets import load_diabetes
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import train_test_split
from lime_ndt import LimeNdtExplainer
# Load data and train a model
diabetes = load_diabetes()
X_train, X_test, y_train, y_test = train_test_split(diabetes.data, diabetes.target, random_state=42)
rf = RandomForestRegressor(random_state=42).fit(X_train, y_train)
# Explain a prediction
explainer = LimeNdtExplainer(X_train, feature_names=diabetes.feature_names,
discretize_continuous=True, mode='regression')
exp = explainer.explain_instance(X_test[0], rf.predict, num_features=10)
# Show results
print(exp.as_list())
exp.as_pyplot_figure()
Advanced Usage
You can customize the NDT surrogate parameters (gammas, tree depth, training epochs):
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from lime_ndt import LimeNdtExplainer, NDTRegressorWrapper
# Load data and train a model
iris = load_iris()
X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, random_state=42)
rf = RandomForestClassifier(random_state=42).fit(X_train, y_train)
# Create explainer
explainer = LimeNdtExplainer(X_train, feature_names=iris.feature_names,
class_names=iris.target_names.tolist(), mode='classification')
# Custom NDT surrogate with specific parameters
ndt = NDTRegressorWrapper(gammas=[1, 100], max_depth=10, epochs=50)
exp = explainer.explain_instance(X_test[0], rf.predict_proba, model_regressor=ndt)
print(exp.as_list())
Features
- Enhanced LIME explanations using Neural Decision Trees.
- Support for tabular data (classification and regression).
- NDT surrogate used by default — no extra setup needed.
- Tools for extracting, analyzing, and comparing decision trees and forests.
- Utilities for discretization (quartile, decile, entropy).
- Integration with Keras and scikit-learn.
Requirements
- Python 3.9+
- numpy, pandas, scikit-learn, keras, tensorflow, matplotlib
How to cite
Mohamed Aymen Bouyahia and Argyris Kalogeratos, Enhancing LIME using Neural Decision Trees, arXiv preprint, http://arxiv.org/abs/2603.20919, 2026.
License
This project is licensed under the Apache License 2.0. See the LICENSE file for details.
Metadata
Release files for lime-ndt 0.2.0
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 |
|---|---|---|---|---|
| lime_ndt-0.2.0.tar.gz | 279.9 kB | Without provenance | Details for lime_ndt-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lime_ndt-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for lime_ndt-0.2.0-py3-none-any.whl |
Total release size: 566.1 kB
Release files / lime_ndt-0.2.0.tar.gz
| Download URL | lime_ndt-0.2.0.tar.gz |
|---|---|
| Size | 279.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fd15a2acf8e585f1ba38e8b4f73e3111da44684e9e8094a672a3f80aa73a302a
|
|
BLAKE2b-256 checksum How to use checksums |
a23e80514bd1966075ec21961b0b022b3aa0571a2ed9a907364433f84c9415b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.11
|
Release files / lime_ndt-0.2.0-py3-none-any.whl
| Download URL | lime_ndt-0.2.0-py3-none-any.whl |
|---|---|
| Size | 286.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3b569eb5e85ad1f49f011157a7e4a9ea4bc7b361adbdc39219f88d6dbc96e663
|
|
BLAKE2b-256 checksum How to use checksums |
165f0e2fd4c776edf7b9a4f91fc5ad3a1b4d2035febe53355c222d33f23d377d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.11
|
Security for lime-ndt 0.2.0
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.