Skip to main content

A Pure Python Implementation of Multivariate Adaptive Regression Splines

Project description

mars: A Pure Python Implementation of Multivariate Adaptive Regression Splines (formerly pymars)

CI Security Code Quality Documentation Code Coverage PyPI Python Version License

mars (formerly pymars) is a pure Python implementation of Multivariate Adaptive Regression Splines (MARS), inspired by the popular py-earth library by Jason Friedman and an R package earth by Stephen Milborrow. The goal of mars is to provide an easy-to-install, scikit-learn compatible version of the MARS algorithm without C/Cython dependencies.

Documentation

Complete documentation is available at: https://edithatogo.github.io/mars/ (once GitHub Pages is configured)

Key Features

  • Pure Python: Easy to install and use across different platforms.
  • Scikit-learn Compatible: Integrates with the scikit-learn ecosystem (estimators, pipelines, model selection tools).
  • MARS Algorithm: Implements the core MARS fitting procedure, including:
    • Forward pass to select basis functions (both hinge and linear terms).
    • Pruning pass using Generalized Cross-Validation (GCV) to prevent overfitting.
    • Support for interaction terms (including interactions involving linear terms).
    • Refined minspan and endspan controls for knot placement, aligning more closely with py-earth behavior (e.g., minspan as a cooldown period).
  • Feature Importance: Calculation of feature importances using methods like 'nb_subsets' (number of subsets in pruning trace), 'gcv' (GCV improvement), and 'rss' (RSS reduction).
  • Regression and Classification: Provides EarthRegressor and EarthClassifier classes.
  • Generalized Linear Models: The GLMEarth subclass fits logistic or Poisson models.
  • Cross‑Validation Helper: The EarthCV class integrates with scikit‑learn's model selection utilities.
  • Plotting Utilities: Simple diagnostics built on matplotlib.
  • Advanced Interpretability: Partial dependence plots, Individual Conditional Expectation (ICE) plots, and model explanation tools.
  • Comprehensive CLI: Command-line interface for model fitting, prediction, and evaluation.

Key Features

  • Pure Python: Easy to install and use across different platforms.
  • Scikit-learn Compatible: Integrates with the scikit-learn ecosystem (estimators, pipelines, model selection tools).
  • MARS Algorithm: Implements the core MARS fitting procedure, including:
    • Forward pass to select basis functions (both hinge and linear terms).
    • Pruning pass using Generalized Cross-Validation (GCV) to prevent overfitting.
    • Support for interaction terms (including interactions involving linear terms).
    • Refined minspan and endspan controls for knot placement, aligning more closely with py-earth behavior (e.g., minspan as a cooldown period).
  • Feature Importance: Calculation of feature importances using methods like 'nb_subsets' (number of subsets in pruning trace), 'gcv' (GCV improvement), and 'rss' (RSS reduction).
  • Regression and Classification: Provides EarthRegressor and EarthClassifier classes.
  • Generalized Linear Models: The GLMEarth subclass fits logistic or Poisson models.
  • Cross‑Validation Helper: The EarthCV class integrates with scikit‑learn's model selection utilities.
  • Plotting Utilities: Simple diagnostics built on matplotlib.
  • Advanced Interpretability: Partial dependence plots, Individual Conditional Expectation (ICE) plots, and model explanation tools.
  • Comprehensive CLI: Command-line interface for model fitting, prediction, and evaluation.

Project Status

This project is currently in the initial development phase. The core algorithm and scikit-learn compatibility are being built. See ROADMAP.md and TODO.md for more details on the development plan and progress.

Installation

Note: Install mars inside a Python virtual environment to silence pip warnings about running as root.

mars can be installed from TestPyPI:

pip install mars

To work with the latest source, clone the repository and install it in editable mode:

git clone https://github.com/edithatogo/mars.git
cd mars
pip install -e .

If you need to run scikit-learn's full estimator checks, install the optional pandas dependency:

pip install "mars[pandas]"

After installation you can check the installed version:

mars --version

Running Tests

Install the dependencies listed in requirements.txt before running the test suite. A small helper script is provided:

# Option 1: directly with pip
pip install -r requirements.txt

# To run the full scikit-learn estimator checks, install the optional pandas
# dependency as well:
pip install "mars[pandas]"

# Option 2: using the helper script
bash scripts/setup_tests.sh

After the dependencies are installed, run the tests with:

pytest

Usage

Quick demos

Run the included demo scripts to see mars in action:

python -m mars.demos.basic_regression_demo
python -m mars.demos.basic_classification_demo

Basic API

import numpy as np
import mars as earth

X = np.random.rand(100, 3)
y = np.sin(X[:, 0]) + X[:, 1]

model = earth.Earth(max_degree=1, penalty=3.0)
model.fit(X, y)
predictions = model.predict(X)

Documentation

The mars project uses a multi-branch documentation approach:

  • Code Documentation: API and development documentation is available in the docs branch
  • Research Paper: The academic paper describing mars is available in the paper branch

For usage examples and tutorials, check the examples directory in this main branch.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md and AGENTS.md for guidelines.

Citing mars

If you use mars in your research, please cite it as follows:

@software{mars2026,
  author = {Mordaunt, Dylan A.},
  title = {mars: A Pure Python Implementation of Multivariate Adaptive Regression Splines},
  year = {2026},
  url = {https://github.com/edithatogo/mars},
  version = {1.0.1},
  license = {Apache-2.0},
}

A CITATION.cff file is also included in the repository for easy citation management.

License

This project is licensed under the Apache 2.0 License.

Acknowledgements

  • Based on the work of Jerome H. Friedman on MARS.
  • Inspired by the py-earth library (scikit-learn-contrib).
  • Inspired by the R earth package.

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

mars_earth-1.0.1.tar.gz (74.0 kB view details)

Uploaded Source

Built Distribution

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

mars_earth-1.0.1-py3-none-any.whl (54.0 kB view details)

Uploaded Python 3

File details

Details for the file mars_earth-1.0.1.tar.gz.

File metadata

  • Download URL: mars_earth-1.0.1.tar.gz
  • Upload date:
  • Size: 74.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mars_earth-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a2562d0fa012f754740b3657605b8c02f9acd77e3a9b4a964674798bcefc31ea
MD5 0593b40e7986ad1602754db281cf6553
BLAKE2b-256 1882dd9739aa2f6938aee642fb95ef5ed25445b3dec14fc36f883ed7058c299a

See more details on using hashes here.

Provenance

The following attestation bundles were made for mars_earth-1.0.1.tar.gz:

Publisher: release.yml on edithatogo/mars

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mars_earth-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: mars_earth-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 54.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mars_earth-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2acc1cee906a18de86c19ba98c0acde76a9a790b9905473daa737ce5a3a79964
MD5 873e10314d2ec387e2ca02ca6eff6039
BLAKE2b-256 be9dbbea42a4453128c950c8b5f575528fd78534dc3fc350977385f5e492234b

See more details on using hashes here.

Provenance

The following attestation bundles were made for mars_earth-1.0.1-py3-none-any.whl:

Publisher: release.yml on edithatogo/mars

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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