mars: A Pure Python Implementation of Multivariate Adaptive Regression Splines (formerly pymars)
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
minspanandendspancontrols for knot placement, aligning more closely withpy-earthbehavior (e.g.,minspanas 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
EarthRegressorandEarthClassifierclasses. - Generalized Linear Models: The
GLMEarthsubclass fits logistic or Poisson models. - Cross‑Validation Helper: The
EarthCVclass 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
minspanandendspancontrols for knot placement, aligning more closely withpy-earthbehavior (e.g.,minspanas 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
EarthRegressorandEarthClassifierclasses. - Generalized Linear Models: The
GLMEarthsubclass fits logistic or Poisson models. - Cross‑Validation Helper: The
EarthCVclass 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-earthlibrary (scikit-learn-contrib). - Inspired by the R
earthpackage.
Metadata
Release files for mars-earth 1.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mars_earth-1.0.4.tar.gz | 78.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mars_earth-1.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 133.2 kB
Release files / mars_earth-1.0.4.tar.gz
| Download URL | mars_earth-1.0.4.tar.gz |
|---|---|
| Size | 78.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0755aa79c879e06bb83d5e2811435c20e4f81623e1ddd8451b528cd8fe6d7972
|
|
BLAKE2b-256 checksum How to use checksums |
b0409a6f04e51950d11de4fac75a5a99efb479f569ff0b251ad145a562c15129
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Apr 17, 2026.
Transparency logRelease files / mars_earth-1.0.4-py3-none-any.whl
| Download URL | mars_earth-1.0.4-py3-none-any.whl |
|---|---|
| Size | 54.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8e7b2386a0f69ab64e97713455df34dd4b84edb787dfaba975175a63519a6e70
|
|
BLAKE2b-256 checksum How to use checksums |
a2fdc22be401631dfff81ef6104854406c5691c3d35d895dbdba2a134e9758bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Apr 17, 2026.
Transparency log