Skip to main content

models.CannFit

A fitted CANN, from Cann.fit.

Usage

Source

models.CannFit()

Attributes

Name Description
best_epoch With early stopping, the epoch (from 1) whose network was kept.
dispersion Dispersion: 1 for the Poisson, otherwise Pearson’s estimate on the
fitted Fitted means on the training rows.
input_hash Hash of the training data (design, offset, weights, response).
validation_history With early stopping, the validation mean deviance after each epoch.

best_epoch

With early stopping, the epoch (from 1) whose network was kept.

best_epoch: int | None


dispersion

Dispersion: 1 for the Poisson, otherwise Pearson’s estimate on the

dispersion: float

training data.


fitted

Fitted means on the training rows.

fitted: list[float]


input_hash

Hash of the training data (design, offset, weights, response).

input_hash: str


validation_history

With early stopping, the validation mean deviance after each epoch.

validation_history: list[float]

Methods

Name Description
correction() The network’s correction to the linear predictor, NN(x), per row.
from_json() Reads an artifact written by to_json.
predict() Expected response for each row of design (same columns as the
predict_distribution() Joint predictive distribution across the rows, keyed ``row = 0, 1,
to_json() The fit as a JSON artifact (spec, scaling, every weight by its path,

correction()

The network’s correction to the linear predictor, NN(x), per row.

Usage

Source

correction(design)

from_json()

Reads an artifact written by to_json.

Usage

Source

from_json(text)
Parameters
text: str
Returns
CannFit
Raises
ValueError
For malformed JSON, another format, a newer format version or weights that do not fit the spec.

predict()

Expected response for each row of design (same columns as the

Usage

Source

predict(design)

training design), g^-1(offset + NN(x)).


predict_distribution()

Joint predictive distribution across the rows, keyed ``row = 0, 1,

Usage

Source

predict_distribution(design, n_sims, seed)

…``: process draws from the family around the predicted means (a trained network carries no parameter uncertainty).

Parameters
design: Design
n_sims: int
seed: int
Returns
PredictiveDistribution

to_json()

The fit as a JSON artifact (spec, scaling, every weight by its path,

Usage

Source

to_json()

fitted values, provenance); from_json reads it back exactly and pickling uses it too.

Returns
str
Examples
>>> import pickle
>>> from prospicio.models import Cann, Design
>>> d = Design([[0.0, 1.0, 2.0, 3.0]], ["x"])
>>> fit = Cann("poisson", hidden=[4], epochs=5).fit(d, [1.0, 2.0, 2.0, 5.0])
>>> pickle.loads(pickle.dumps(fit)).predict(d) == fit.predict(d)

True