## models.MarsFit


The knots MARS selected, from [mars](models.mars.md#prospicio.models.mars): each term as


Usage

``` python
models.MarsFit()
```


`(name, knot, direction)`, with direction `"up"` for `max(0, x - k)`, `"down"` for `max(0, k - x)` and `"linear"` for [x](distributions.Ogive.md#prospicio.distributions.Ogive.x).


## Attributes

| Name | Description |
|----|----|
| [coefficients](#coefficients) | The intercept and each selected term's coefficient. |
| [forward_terms](#forward_terms) | The forward pass's terms, before the backward pass. |
| [gcv](#gcv) | The GCV of the selected terms. |
| [grsq](#grsq) | `1 - gcv / gcv0`. |
| [names](#names) | The predictors' names. |
| [rsq](#rsq) | `1 - rss / rss0`. |
| [rss](#rss) | The (weighted) residual sum of squares, or the GLM's deviance. |
| [steps](#steps) | The forward pass step by step: the terms each added, and the RSS |
| [termination](#termination) | Why the forward pass stopped: `"no_improvement"`, |
| [terms](#terms) | The selected terms `(name, knot, direction)`, in the order the |

------------------------------------------------------------------------


#### coefficients


The intercept and each selected term's coefficient.


`coefficients: list[float]`


------------------------------------------------------------------------


#### forward_terms


The forward pass's terms, before the backward pass.


`forward_terms: list[tuple[str, float, str]]`


------------------------------------------------------------------------


#### gcv


The GCV of the selected terms.


`gcv: float`


------------------------------------------------------------------------


#### grsq


`1 - gcv / gcv0`.


`grsq: float`


------------------------------------------------------------------------


#### names


The predictors' names.


`names: list[str]`


------------------------------------------------------------------------


#### rsq


`1 - rss / rss0`.


`rsq: float`


------------------------------------------------------------------------


#### rss


The (weighted) residual sum of squares, or the GLM's deviance.


`rss: float`


------------------------------------------------------------------------


#### steps


The forward pass step by step: the terms each added, and the RSS


`steps: list[dict]`


(or deviance), R² and GCV after it.


------------------------------------------------------------------------


#### termination


Why the forward pass stopped: `"no_improvement"`,


`termination: str`


`"threshold"`, `"gcv"`, `"rsq"` or `"max_terms"`.


------------------------------------------------------------------------


#### terms


The selected terms `(name, knot, direction)`, in the order the


`terms: list[tuple[str, float, str]]`


forward pass added them, without the intercept.


## Methods

| Name | Description |
|----|----|
| [add_terms()](#add_terms) | [terms](models.MarsFit.md#prospicio.models.MarsFit.terms) with each selected predictor added: [numeric](models.Terms.md#prospicio.models.Terms.numeric) when |
| [from_json()](#from_json) | Reads an artifact written by [to_json](models.Terms.md#prospicio.models.Terms.to_json). |
| [knots()](#knots) | The sorted knots of [name](aggregate.Ledger.md#prospicio.aggregate.Ledger.name)'s hinges, for [Terms.hinges](models.Terms.md#prospicio.models.Terms.hinges). |
| [linear()](#linear) | Whether [name](aggregate.Ledger.md#prospicio.aggregate.Ledger.name) enters linearly besides its hinges. |
| [to_json()](#to_json) | The fit as a versioned JSON artifact: the names, the selected and |

------------------------------------------------------------------------


#### add_terms()


[terms](models.MarsFit.md#prospicio.models.MarsFit.terms) with each selected predictor added: [numeric](models.Terms.md#prospicio.models.Terms.numeric) when


Usage

``` python
add_terms(terms)
```


[linear](models.MarsFit.md#prospicio.models.MarsFit.linear) and [hinges](models.Terms.md#prospicio.models.Terms.hinges) at its [knots](models.MarsFit.md#prospicio.models.MarsFit.knots), spanning the selected terms.


##### Parameters


`terms: Terms`  


##### Returns


`Terms`  


------------------------------------------------------------------------


#### from_json()


Reads an artifact written by [to_json](models.Terms.md#prospicio.models.Terms.to_json).


Usage

``` python
from_json(text)
```


##### Parameters


`text: str`  


##### Returns


`MarsFit`  


##### Raises


`ValueError`  
For malformed JSON, another format, a newer format version or inconsistent fields.


------------------------------------------------------------------------


#### knots()


The sorted knots of [name](aggregate.Ledger.md#prospicio.aggregate.Ledger.name)'s hinges, for [Terms.hinges](models.Terms.md#prospicio.models.Terms.hinges).


Usage

``` python
knots(name)
```


------------------------------------------------------------------------


#### linear()


Whether [name](aggregate.Ledger.md#prospicio.aggregate.Ledger.name) enters linearly besides its hinges.


Usage

``` python
linear(name)
```


------------------------------------------------------------------------


#### to_json()


The fit as a versioned JSON artifact: the names, the selected and


Usage

``` python
to_json()
```


forward terms, the forward pass's steps, the coefficients and the fit statistics, with the GLM fitted on the terms when [family](risk.Distortion.md#prospicio.risk.Distortion.family) was given; numbers bit for bit (#978). [from_json](models.Terms.md#prospicio.models.Terms.from_json) reads it back; `pickle` uses the same document.


##### Returns


`str`  


##### Examples

``` python
>>> import pickle
>>> from prospicio.models import MarsFit, mars
>>> x = [float(i) for i in range(60)]
>>> fit = mars({"x": x}, [1 + 0.5 * v + 3 * max(0.0, v - 31) for v in x])
>>> MarsFit.from_json(fit.to_json()).knots("x")
```

\[31.0\]

``` python
>>> pickle.loads(pickle.dumps(fit)).coefficients == fit.coefficients
```

True
