Skip to main content

Enhancing LIME through Neural Decision Trees

Project description

PyPI Downloads License Vulnerabilities Bug

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.

Features

  • Enhanced LIME explanations using Neural Decision Trees.
  • Support for tabular data.
  • Tools for extracting, analyzing, and comparing decision trees and forests.
  • Utilities for submodular pick and discretization.
  • Integration with Keras and scikit-learn.

Example Usage

Below is a minimal example showing how to use lime_ndt to explain a regression model on the diabetes dataset:

from sklearn.datasets import load_diabetes
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor
from lime_ndt.lime_tabular import LimeNdtExplainer
from lime_ndt.utils.ndt_sklearn_wrapper import NDTRegressorWrapper
import matplotlib.pyplot as plt

# Load the diabetes dataset
diabetes = load_diabetes()
X = diabetes.data
y = diabetes.target

# Split into train/test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)

# Train a Random Forest regressor
rf = RandomForestRegressor(random_state=42)
rf.fit(X_train, y_train)

# Prediction function
def predict_fn(X):
    return rf.predict(X)

# Create the LIME explainer
explainer = LimeNdtExplainer(
    X_train,
    feature_names=diabetes.feature_names,
    class_names=None,
    discretize_continuous=True,
    mode='regression',
)

# Create the local NDT model
model_regressor = NDTRegressorWrapper(D=X_train.shape[1])  # gamma=[1,100] , max_depth = 5

# Explain a test instance
exp = explainer.explain_instance(
    X_test[8],
    predict_fn,
    num_features=10,
    model_regressor=model_regressor
)

# Visualize the explanation
exp.as_pyplot_figure()
plt.show()
image

Requirements

  • Python 3.7+
  • numpy, pandas, scikit-learn, keras, tensorflow, matplotlib

See requirements.txt for the full list.

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.

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

lime_ndt-0.1.6.tar.gz (39.4 kB view details)

Uploaded Source

Built Distribution

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

lime_ndt-0.1.6-py3-none-any.whl (42.9 kB view details)

Uploaded Python 3

File details

Details for the file lime_ndt-0.1.6.tar.gz.

File metadata

  • Download URL: lime_ndt-0.1.6.tar.gz
  • Upload date:
  • Size: 39.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for lime_ndt-0.1.6.tar.gz
Algorithm Hash digest
SHA256 2ffec57350e54b8156fd9580c919a4b7a5e5931bf28ca3770cf0db9e2a734154
MD5 6273c4c94cb77008cb09a46bda5bff79
BLAKE2b-256 a158260697d8453c52374b7fd682ea5b88103d768f2c4c9fb42a2c7406f445ca

See more details on using hashes here.

File details

Details for the file lime_ndt-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: lime_ndt-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 42.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for lime_ndt-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 43ece4350f6644437dc2d42ed9345a61bfaa681fef5ee3f2cf3d1d5f750273db
MD5 d4453e27b139752b6944a219cedc96fe
BLAKE2b-256 1a410ae9a3bc331dedc348fac882e23093fe21e8e8b03a4ea72f3f7d3db10548

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