milia.core.io#
Saving and loading fitted estimators.
Every milia estimator pickles cleanly, so persistence is joblib plus a small JSON manifest recording what was saved and with which milia version.
Functions
|
Load an estimator saved with |
|
Save a fitted estimator to a directory. |
- milia.core.io.save(estimator, path)#
Save a fitted estimator to a directory.
Writes the estimator with joblib as
model.jobliband amanifest.jsonrecording its class, module, the milia version and the time it was saved.- Parameters:
- Return type:
- Returns:
The directory written to.
Examples
>>> import tempfile, numpy as np >>> from milia import make >>> model = make("detector", "ecod").fit(np.random.default_rng(0).normal(size=(50, 2))) >>> folder = save(model, tempfile.mkdtemp()) >>> sorted(p.name for p in folder.iterdir()) ['manifest.json', 'model.joblib']
- milia.core.io.load(path)#
Load an estimator saved with
save().Only load directories you trust: joblib files can execute code when loaded.
- Parameters:
- Return type:
- Returns:
The fitted estimator.
Examples
>>> import tempfile, numpy as np >>> from milia import make >>> X = np.random.default_rng(0).normal(size=(50, 2)) >>> model = make("detector", "ecod").fit(X) >>> again = load(save(model, tempfile.mkdtemp())) >>> bool(np.allclose(again.score_samples(X), model.score_samples(X))) True