## models.cross_validate()


Fits [model](reserving.OneYearFit.md#prospicio.reserving.OneYearFit.model) on each split's training rows and scores it on the


Usage

``` python
models.cross_validate(
    model,
    design,
    y,
    splits,
    score,
    n_jobs=None,
)
```


test rows.

Folds run on threads; the Rust fits release the GIL, so they run in parallel.


## Parameters


`model: object`  
Anything with `fit(design, y)` returning an object with `predict(design)`: [Glm](models.Glm.md#prospicio.models.Glm), [ElasticNet](models.ElasticNet.md#prospicio.models.ElasticNet), [Gam](models.Gam.md#prospicio.models.Gam).

`design: Design`  

`y: list of float`  

`splits: list of (list of int, list of int)`  
`(train, test)` rows, as [k_fold](models.k_fold.md#prospicio.models.k_fold) returns.

`score: callable`  
`score(y_test, predicted, test_design) -> float`, a loss (lower is better), such as `deviance_score("poisson")`.

`n_jobs: int = None`  
Threads; one per split by default.


## Returns


`list of float`  
One score per split.


## Examples

``` python
>>> from prospicio.models import Design, Glm, cross_validate, deviance_score, k_fold
>>> d = Design([[1.0] * 6, [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]], ["(Intercept)", "x"])
>>> y = [1.0, 2.9, 5.1, 7.0, 8.9, 11.2]
>>> scores = cross_validate(Glm("gaussian"), d, y, k_fold(6, 3, 1), deviance_score("gaussian"))
>>> len(scores)
```

3
