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.3.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.3-py3-none-any.whl (54.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mars_earth-1.0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 d0ab7a96673f668b639aac36e621c76040f4a17990aaa02445eaa05e520922b7
MD5 ef822d2521894cf383a5ad525a356536
BLAKE2b-256 1e351853b1b270e399bae53241a89a20de1ae5d224ce71e63339e2b304d63557

See more details on using hashes here.

Provenance

The following attestation bundles were made for mars_earth-1.0.3.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.3-py3-none-any.whl.

File metadata

  • Download URL: mars_earth-1.0.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cc9c9daa0168e9b5fb16a670432435b3ff4bdf100404b57e3cc15aa75b310969
MD5 fb138f03d9be548c95f91dd3b3ef9ddb
BLAKE2b-256 12b854a238844f8ff2b938cb91d500a3a72ad98febbf121288c073711d188d67

See more details on using hashes here.

Provenance

The following attestation bundles were made for mars_earth-1.0.3-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