Skip to main content

LUNA-XAI

Local Understanding through Neighborhood Analysis for Explainable AI

LUNA is a Python library for model-agnostic explainability on tabular machine learning models.
It focuses on local explanations built from neighborhood analysis (HNSW), sensitivity analysis (DSA-style), and a Calinski–Harabasz-based importance metric with robust normalization.

The current version accepts data managed by pandas and sklearn models and pipelines.

LUNA is designed to be:

  • Model-agnostic — works with any sklearn-like estimator (regression or classification).
  • Tabular-first — optimized for tabular problems with mixed numerical & categorical features.
  • Neighborhood-based — uses HNSW neighbors + synthetic sampling (LHS, CTGAN) for local exploration.
  • Metric-driven — feature importances derived from CH-style separability scores, with optional arctan normalization.
  • Extensible — pluggable methods, metrics, renderers, and domains.

Main Features

  • Hybrid preprocessing for neighbors

    • HybridPreprocessor with:
      • Optional CANE IDF encoding for categorical features.
      • Global scaling via StandardScaler (configurable).
      • Fully numeric representation to build HNSW indices.
  • Efficient neighborhood search

    • HNSW index via hnswlib:
      • HNSWBuilder + HNSWIndexManager.
      • Save/load index and metadata separately from training data.
  • Local sensitivity analysis (DSA-style)

    • DSAMethod:
      • Finds neighbors in hybrid space.
      • Generates synthetic samples via:
        • Empirical LHS (LatinHypercube from scipy.stats.qmc).
        • CTGAN (optional, if installed).
      • Perturbs features over discretized levels for sensitivity analysis.
  • CH-based metric with sign & normalization

    • CHMetric + utilities:
      • calculate_ch_index() — per-feature CH-like separability across levels.
      • adjust_signal() — flips sign based on monotonic trend direction.
      • arctan_normalize() — squashes importances to [-1, 1] for stability.
  • Explainers

    • TabularRegressionExplainer
      • Works on predictions y_hat.
      • 2-stage design:
        1. generate_explanation_data() → sensitivity data.
        2. explain_from_data() → importances + rendering.
    • TabularClassificationExplainer
      • Uses predict_proba for the predicted class (argmax).
      • Passes target_class down to the method for class-conditional analysis.
  • Plotting & rendering

    • PlotRenderer + MatplotlibPngExporter:

      • Local feature importances (horizontal bars).

      LUNA Feature Importance)

      • ICE-like line plots (feature trends).

      LUNA ICE-style Plot

      • Per-feature vec boxplots for sensitivity distributions.

      LUNA VEC Boxplot

    • Low-level plotting helpers in luna_xai.utils.plotting.

  • Logging utilities

    • logging_utils:
      • get_luna_logger() — scoped loggers under luna_xai.
      • configure_luna_logging() — console/file configuration.
      • log_execution_segment() — context manager for timing segments.

Documentation

Complete documentation is available at:

LUNA XAI Documentation

Complete tutorials, and examples are available at:

LUNA XAI Classification Demo

LUNA XAI Regression Demo

📦 Installation

Prerequisites: Python >=3.11, <3.13 and a C++ toolchain (for hnswlib).

Windows Installation Notes

On Windows, the hnswlib dependency may require a C++ compiler to be installed, as precompiled binaries may not be available for all Python versions.

If installation fails with an error such as:

error: Microsoft Visual C++ 14.0 or greater is required.

Install the Microsoft C++ Build Tools and select the Desktop development with C++ workload, including the MSVC compiler and Windows SDK.

After installation, restart your terminal and retry:

pip install luna-xai

This requirement comes from the hnswlib dependency and does not require any changes to the LUNA source code.

Disclaimer and Limitations

This package is provided under the MIT License and is intended to support the interpretation and analysis of machine learning models.

As with other explainable AI methods, the generated explanations are subject to methodological assumptions and may vary depending on the underlying model, data, and configuration. They should be interpreted within the context of the specific application and are not guaranteed to accurately or completely represent the model's behavior in every scenario.

Users are encouraged to assess the suitability of the explanations for their intended use and exercise appropriate judgment when incorporating them into decision-making processes.

The software is provided "AS IS", without warranties of any kind. To the maximum extent permitted by applicable law, the authors and contributors shall not be liable for any claims, damages, losses, or other liabilities arising from the use of, inability to use, or reliance upon the software or its outputs, including inaccurate, incomplete, or misleading explanations.

For further details, please refer to the MIT License.

Metadata

Release files for luna-xai 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for luna-xai 0.1.6
File Size Uploaded Provenance Actions
luna_xai-0.1.6.tar.gz 2.6 MB With provenance Details for luna_xai-0.1.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for luna-xai 0.1.6
File Interpreter ABI Platform Actions
luna_xai-0.1.6-py3-none-any.whl Python 3 none any Details for luna_xai-0.1.6-py3-none-any.whl

Total release size: 5.3 MB

Release files / luna_xai-0.1.6.tar.gz

Download URL luna_xai-0.1.6.tar.gz
Size 2.6 MB
Tags Source
SHA-256 checksum
How to use checksums
2c23396749e63989b17d62b4740c533e9db0489148ec585eb8130f23572c527e
BLAKE2b-256 checksum
How to use checksums
e6a1efc115fb4012f31ca4ec731abaa9ac032ed686013ad2989e9c228f847785
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 23, 2026.

Transparency log

Release files / luna_xai-0.1.6-py3-none-any.whl

Download URL luna_xai-0.1.6-py3-none-any.whl
Size 2.7 MB
Tags Python 3
SHA-256 checksum
How to use checksums
848d63668888125477683ec48a07e1b6d81ae155868ed2101bfaa72af1754d79
BLAKE2b-256 checksum
How to use checksums
70775ae165f535d264dcf26a2f0e077f07ede96e2e5c46c8afb4a403a9164060
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 23, 2026.

Transparency log

Security for luna-xai 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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for luna_xai-0.1.6.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 23, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page