Save, load and refit¶
Save and load¶
A fitted estimator can be written to a file and restored without refitting.
Serialization uses pickle, so only load files you trust:
>>> import freqprob
>>> model = freqprob.Laplace({"a": 5, "b": 3}, bins=100, logprob=False)
>>> model.save("model.pkl")
>>> restored = freqprob.Laplace.load("model.pkl")
>>> restored("a") == model("a")
True
load checks that the file holds an estimator of the class it is called on.
Refit¶
fit refits an estimator to new counts, keeping its parameters, and returns
it, so calls can be chained:
revision increases at every refit, so code that caches scores can tell when
to rebuild them.
The scikit-learn-style API¶
Alongside calling the estimator, score scores one element and predict
scores many: