mars (formerly pymars) is a mars implementation project moving from a
pure Python training implementation toward a shared Rust computational core
surfaced through Python, R, Julia, Rust, C#, Go, and TypeScript APIs. It is
inspired by Jerome H. Friedman's mars work and by prior open-source APIs such as
py-earth and R earth, but it does not depend on those packages for
implementation or validation.
Complete documentation is published at: https://edithatogo.github.io/mars/
- Python API Today: Easy to install and use with a scikit-learn-compatible Python interface.
- Rust Core Direction: Shared fitting and runtime evaluation logic is moving toward a Rust core.
- 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.
- Portable Model Export: Export fitted
Earthmodels to a versioned JSON model spec and replay them without relying on pickle or Python object reconstruction. - Cross-Runtime Fixture Coverage: Checked-in portable fixtures are validated by the Python runtime and a Rust reference runtime.
- Binding Roadmap: The target surface spans Python, R, Julia, Rust, C#, Go, and TypeScript.
- Comprehensive CLI: Command-line interface for model fitting, prediction, and evaluation.
The project is in active beta. The current Python mars implementation,
sklearn-compatible estimators, portable ModelSpec contract, and Rust reference
runtime fixture validation are in place. Current roadmap work should keep the
Python API stable while moving shared computation toward a Rust core that can
power Python, R, Julia, Rust, C#, Go, and TypeScript bindings.
Near-term priorities are:
- stabilizing the portable JSON model contract
- hardening persistence and numerical-regression testing with checked-in fixtures
- growing the Rust replay prototype into the shared Rust core
- defining shared conformance tests for Python, R, Julia, Rust, C#, Go, and TypeScript bindings
- widening platform bindings and long-term API stability guarantees
Note: Install mars inside a Python virtual environment to silence pip warnings about running as root.
Install the published distribution from PyPI:
pip install mars-earthThe distribution name is mars-earth, but the import name remains pymars.
The supported compatibility style is:
import pymars as earthTo 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 DataFrame-aware estimator checks, install the optional pandas dependency:
pip install "mars-earth[pandas]"After installation you can check the installed version:
mars --versionInstall 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.shAfter the dependencies are installed, run the tests with:
pytest
Run the included demo scripts to see mars in action:
python -m pymars.demos.basic_regression_demo
python -m pymars.demos.basic_classification_demoimport numpy as np
import pymars 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)import pymars as earth
model = earth.Earth().fit(X, y)
earth.save_model(model, "model.json")
validated = earth.validate("model.json")
spec = earth.load_model_spec("model.json")
portable = earth.load_model("model.json")
features = earth.design_matrix("model.json", X)
predictions = portable.predict(X)
runtime_predictions = earth.predict("model.json", X)Stable estimators:
pymars.Earthpymars.EarthRegressorpymars.EarthClassifier
Stable portability/runtime helpers:
pymars.validatepymars.load_model_specpymars.load_modelpymars.save_modelpymars.predictpymars.design_matrixpymars.inspect
Stable utility exports:
pymars.CategoricalImputer- Plotting helpers re-exported from
pymars.visualization
Experimental APIs:
pymars.EarthCVpymars.GLMEarth
Undocumented internal imports are not part of the supported public API.
The repository ships source documentation for mkdocs in docs/ and publishes the built site through GitHub Pages. For usage examples and tutorials, check the examples directory and the pymars/demos/ modules.
Contributions are welcome! Please see CONTRIBUTING.md and AGENTS.md for guidelines.
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.4},
license = {Apache-2.0},
}A CITATION.cff file is also included in the repository for easy citation management.
This project is licensed under the Apache 2.0 License.
- Based on the work of Jerome H. Friedman on mars.
- API ideas were informed by
py-earthand Rearth, but mars does not depend on either package for implementation or validation.