Skip to main content

models.AttentionCannFit

A fitted attention CANN, from AttentionCann.fit.

Usage

Source

models.AttentionCannFit()

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.
fitted Fitted means on the training rows.
input_hash Hash of the training data (design, offset, weights, response).
tokens Feature tokens, in column order.
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.

dispersion: float


fitted

Fitted means on the training rows.

fitted: list[float]


input_hash

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

input_hash: str


tokens

Feature tokens, in column order.

tokens: list[str]


validation_history

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

validation_history: list[float]

Methods

Name Description
attention() The last block’s attention from [CLS] to each feature token, per
correction() The network’s correction to the linear predictor, per row.
from_json() Reads an artifact written by to_json.
predict() Expected response for each row of design.
predict_distribution() Joint predictive distribution across the rows: process draws from
to_json() The fit as a JSON artifact (spec, scaling, every weight by its path,

attention()

The last block’s attention from [CLS] to each feature token, per

Usage

Source

attention(design)

row of design and head: where the model looked for each risk. A diagnostic, not a decomposition of the prediction.

Returns
TokenAttention
Raises
ValueError
If the model has no blocks (layers=0).

correction()

The network’s correction to the linear predictor, per row.

Usage

Source

correction(design)

from_json()

Reads an artifact written by to_json.

Usage

Source

from_json(text)
Parameters
text: str
Returns
AttentionCannFit
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.

Usage

Source

predict(design)

predict_distribution()

Joint predictive distribution across the rows: process draws from

Usage

Source

predict_distribution(design, n_sims, seed)

the family around the predicted means.

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