models.cross_validate()
Fits model on each split’s training rows and scores it on the
Usage
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 withpredict(design): Glm, ElasticNet, Gam. design: Designy: list of floatsplits: list of (list of int, list of int)-
(train, test)rows, as k_fold returns. score: callable-
score(y_test, predicted, test_design) -> float, a loss (lower is better), such asdeviance_score("poisson"). n_jobs: int = None- Threads; one per split by default.
Returns
list of float- One score per split.
Examples
>>> 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