rheon.polars.ModelBank.summary

ModelBank.summary(spec: str | int | None = None, group: str | Iterable[str | None] | None = None) → DataFrame[source]

Return what each model has been fed, one row per spec and group.

Use it after a run to see how many rows each model learned, skipped or reset on, and whether it is warmed up, from the bank or from one loaded from a state file. For each input column’s statistics use describe(), and for findings about the data, check().

Parameters

spec

The spec to read, by name or by position. The default, None, reads every spec.

group

The group to read: one group key, as groups() reports it, or a list of keys, with None in the list for the null group. The default, None, reads every group. A key the bank has never seen gives no rows.

Returns

A DataFrame with one row per (spec, group), in spec order, then in groups()’ order. The counts and ranges cover every row routed to the group since its state began, undecayed, so they say what the model learned from, not what it still remembers. Every count is an Int64. The columns:

spec, group

As groups() reports them.

rows_fed

The rows routed to the group, skipped or not, as groups() counts them.

rows_processed

The rows the models saw: every feature and the weight usable.

rows_skipped

rows_fed - rows_processed: the rows with a null, NaN, infinite or out-of-bound feature or weight.

rows_learned

The processed rows with a positive weight and, for a model with targets, at least one usable target. A formula target’s row counts when it is released with a value, once its window has closed.

rows_zero_weight

The processed rows with weight 0: the clock moved, and nothing was learned.

weight_sum

The sum of the processed rows’ weights, 1 for a row without a weight column. It is undecayed, so it is not the output’s weight_sum field.

clock_min, clock_max, clock_last

The range of the clock fed, and its last value, exactly, in the clock column’s own dtype, as groups() gives clock_last. Null for a spec without a clock.

session_changes

The rows whose session differed from the row before.

clock_backwards

The rows whose clock fell below the row before within a session, which restart_after_step_back decided about.

resets

The rows at which session_gap = "reset" or restart_after_step_back reset the model.

solve_failures

The solves that needed jitter or kept the previous fit, which solve_failures() reports.

refit_given_up

The targets whose refit of their first rows was given up, past the spec’s refit_budget or past the cap on how long its buffer of rows ages. Four models refit their first rows and count it: huber, quantile, sgd(loss="huber"), and a marginal whose bins refit (bin_refit_rows). 0 on every other spec.

labels_missing, labels_dropped

Under label_clock, the rows whose targets were never learned. labels_missing counts the rows not skipped whose label_clock is null. labels_dropped counts the rows held for their label_clock time and dropped, by held_overflow="drop_oldest" or by a clock that reset the model. 0 on every other spec.

settled_frac

How far the first instance (the part of the model that fits the spec’s first half-life) has come toward its steady state under decay, after the last row: the fraction the next row’s settled_frac field reads. Under embargo it counts the clock the held rows have covered too. Null where the model has no such reading.

weight_sum_settled

The weight the model’s weight_sum tops out at, projected from where it stands (see Notes). It says, before the model gets there, whether a min_weight can be met. Null after a single row, with no decay, and under window_size.

error_inflation

The largest ratio the max_error_inflation gate checks, over the first instance’s slots (see Notes). Null where the model has no such gate.

support_coef_min, support_coef_min_feature, n_coef

The smallest coefficient’s data share, the feature it belongs to, and the number of coefficients a target, read from the model’s first instance after the last row, as settled_frac and error_inflation are.

An audit (rheon.spec.audit()) reads every row and learns from none: its rows_processed is rows_fed, its rows_skipped is 0, and its rows_learned and n_coef are null. What it counted is audit()’s.

Raises

KeyError

spec is a name the bank does not have.

IndexError

spec is a position the bank does not have.

TypeError

group is not a str, a list of them with None allowed, or None.

ValueError

spec is None and two specs read clocks of different dtypes, which one clock column cannot hold. Read them one spec at a time, as for groups().

Examples

This code reads df from Example data:

spec = rp.spec.ewridge(
    "ridge", targets=["y"], features=["x0", "x1"], half_life=100.0,
    clock="t", gap_cap=300.0,
)
bank = rp.ModelBank([spec])
holes = pl.when(pl.col("t") % 10 == 0).then(None).otherwise(pl.col("x1"))
bank.fit(df.with_columns(x1=holes))                 # x1 null on every tenth row
row = bank.summary().row(0, named=True)             # one row: the spec has no groups
print(row["rows_fed"], row["rows_processed"], row["rows_skipped"], row["rows_learned"])
400 360 40 360

See also

  • describe(), each input column’s statistics.

  • check(), findings about the data, read from this summary and more.

  • solve_failures(), one of these columns alone.

  • Is it ready?, on settled_frac, error_inflation and weight_sum_settled.

Notes

The counts are kept in the state file, so a bank loaded from a file gives them too. predict() moves none of them, and feeding the same rows in one chunk or a thousand gives the same numbers to the bit.

settled_frac reads the model’s own decay, half_life, as min_settled_frac and the readiness warnings do. It does not read a second memory the model keeps beside it, such as holt’s trend: the diagnostics wait for the longest of those instead (One memory per diagnostic).

error_inflation is ewridge’s sqrt(1 + edf / n_kish), rls’s sqrt(1 + k_total / n_kish) and lasso’s sqrt(1 + df / n_kish). kalman’s gate reads each row’s own value, so its reading here is the gate’s mean over the design, sqrt(1 + sum_i P_ii E[z_i^2] / R).

weight_sum_settled is (W - w1 * (1 - s)) / s. W is the accumulated weight a next row would report as weight_sum, w1 a row’s weight (1 without a weight column, the rows’ mean with one), and s how far the learned rows have come toward their steady state. s is settled_frac except under embargo, where the held rows’ clock is left out: W has neither decayed by nor accumulated them, and the projection pairs a weight with the clock it has covered. On a regular stream, rows d apart of one weight, it is exactly the ceiling 1 / (1 - 2 ** (-d / half_life)) times that weight, from the second row on. It is exactly 0 where W - w1 * (1 - s) is within its own rounding: a model whose weight is still its first row’s alone, which would otherwise read a few 1e-16 above or below 0, by the platform’s math library. The rounding allowed is 8 * 2**-53 times the rows read times W + w1.