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

Uploaded Python 3

File details

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

File metadata

  • Download URL: mars_earth-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 9b1c7a779a1333b29a9718fd4b83a7e27c1e44ba5e9bd31c84013624108e06e1
MD5 4691457cc0a3188a8eeb23c05fdf15ea
BLAKE2b-256 3f076b15fe5b7b41b73b7b5d0171f811472089ab5d2f18f5d1ad971c7ade0113

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: mars_earth-1.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4a3f82f6646d5f0acf71d8331cc7aff52c02f6845402dbd8199a7d6ee1d6fe2c
MD5 26edb87026ca98946a7ae49c4255cb67
BLAKE2b-256 944092f0678c5b9a6612c1819e024dab2c8070ddfc1c20d2426d52aede33b084

See more details on using hashes here.

Provenance

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