Advanced workflows include portable model-spec export, interpretability, and pipeline integration.
import numpy as np
import pymars as earth
X = np.array(
[
[-1.0, 0.0, 0.5],
[-0.2, 0.3, 0.0],
[0.1, -0.4, 0.2],
[0.5, 0.2, -0.3],
[1.0, -0.7, 0.8],
[1.4, -1.1, 1.1],
],
dtype=float,
)
y = np.array([0.8, 1.3, 2.0, 2.6, 4.9, 6.2], dtype=float)
model = earth.Earth(max_degree=1, penalty=3.0)
model.fit(X, y)
spec = model.export_model(format="json")
validated_spec = earth.validate(spec)
explanation = earth.get_model_explanation(model, X)
basis_summary = explanation["basis_functions"]
For a quick visual check, the plotting helpers can be used directly:
from pymars import plot_basis_functions, plot_residuals
plot_basis_functions(model, X)
plot_residuals(model, X, y)
from pymars import plot_individual_conditional_expectation, plot_partial_dependence
plot_partial_dependence(model, X, features=[0, 1])
plot_individual_conditional_expectation(model, X, features=[0])
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
pipeline = Pipeline(
[
("scale", StandardScaler()),
("earth", earth.Earth(max_degree=1, penalty=3.0)),
]
)
pipeline.fit(X, y)
pipeline_predictions = pipeline.predict(X)
The advanced tutorial is intended to demonstrate the broader workflow surface without depending on any unsupported accelerator or distributed-execution behavior.