rheon.ReadinessWarning

class rheon.ReadinessWarning[source]

Bases: RheonWarning, UserWarning

A warning that a model is not ready, or may never become ready.

It points once at a state every row already carries in withheld_reason, settled_frac and support_coef, so you can act before reading the output. Where the finding is intended, filter it out with warnings.simplefilter("ignore", rheon.ReadinessWarning). Is it ready? sets each finding beside the gates that withhold a prediction.

The learning calls issue it: ModelBank.fit(), ModelBank.fit_predict(), ModelBank.fit_predict_batches() and lf.rheon.fit_predict. predict never does. Apart from the two findings about a horizon, it is issued once per spec and group. Its message begins with the spec, and the group where the spec has one, as spec "m" group "g":. Under group_close="session" each session span is a stream of its own, so the warning is issued once per span, which the message names by its session value, as spec "m" group "g" session "a": (session null for a null value). Two spans with the same finding then give two texts, and Python’s default filter, which shows a text once per line of code, shows both.

It reports five findings:

  • A coefficient the ridge determined more than the data did (support_coef below 0.5), named, on a row the gates let through. The features do not determine such a coefficient: a duplicated or constant column, or a ridge as large as the feature’s variance does this. While the columns stay collinear, the predictions do not depend on the split. The split among such columns is arbitrary, and it moves the moment the collinearity breaks.

  • The ``max_error_inflation`` gate has not been met. The gate has withheld every row for a further half-life, and at the row rate so far error_inflation stays above max_error_inflation, so predictions stay withheld unless the rows come faster. The message says how far, and gives a half-life above which the gate is met, or a looser ratio. Where the model has not fit at all, its weight_sum short of a row per coefficient, the message gives where weight_sum tops out instead. A kalman never issues it, since its gate reads each row’s own value, which a row nearer the design’s center reads lower.

  • A min_weight has not been met. The floor has withheld every row for a further half-life, and the weight a target reads tops out below its min_weight. The message names that ceiling (weight_sum_settled in ModelBank.summary()), and the min_weight or half_life that meets it. A target that no row with a positive weight has given a value has no rate to project from, so its message says that instead. A target whose own weight is below weight_sum has not been learned from every row, and its weight falls on each row without it. Its message says so, with the ceiling the floor would have if every row carried the target, where that ceiling is below the floor.

  • A diagnostic has no horizon. A spec with a clock and an embargo but no horizon_rows has a diagnostic that reads the target’s horizon (emit_calibration, emit_breaks, emit_specification or emit_robust_se). There embargo is in clock units, so the horizon is 0, and a target that looks ahead flags the test on most rows. The message names horizon_rows, once per diagnostic, on the bank’s first learning call.

  • The Newey-West lags were capped at 64. Without a clock, embargo is in rows and gives the horizon. A diagnostic that reads the horizon takes twice the horizon in Newey-West lags, and at most 64 when they are read from embargo. The message gives the lags asked for, and names horizon_rows (to take them all) and robust_se_lags. It begins with the spec alone, and comes on the bank’s first learning call.

Offline, rheon.gram.lasso_path() issues it once per call for the penalties whose coordinate descent ran out of its max_iter sweeps before it met its stopping rule, naming them. Each such penalty’s row of the path is where its descent stopped. The lasso model counts the same event in ModelBank.solve_failures(), except on a Gram with too few rows for its features, its warm-up.

Examples

This code reads df from Example data:

import warnings

# 400 rows a step apart, with a half-life of 20 steps: the weight tops out near 29.
spec = rp.spec.ewridge(
    "ridge", targets=["y"], features=["x0", "x1"], clock="t", half_life=20.0,
    gap_cap=5.0, min_weight=50.0,
)
with warnings.catch_warnings(record=True) as caught:
    warnings.simplefilter("always")
    rp.ModelBank([spec]).fit_predict(df)
for w in caught:
    print(type(w.message).__name__, str(w.message).split(" has not")[0])
ReadinessWarning spec "ridge": min_weight = 50

See also

  • Is it ready?, the gates and what each finding means for the output.

  • ModelBank.summary(), whose weight_sum_settled is the ceiling the min_weight finding names.

  • RheonWarning, the base class every warning of this library shares.

Notes

The first three findings judge a model only once its settled_frac reaches 0.95, the model within 5% of its steady state. Before then, its early rows still move what the warning would say, and a warning cannot be taken back: the first rows’ noisy feature variances, for example, can read a share of the data below 0.5 that later rows do not. Where nothing decays, settled_frac is null, so the model is never judged, and its support_coef, withheld_reason and ModelBank.summary() carry what it reads.

The noise-gate and min_weight findings wait a half-life during which their gate withholds every row, on the clock the learned rows have covered. A row the gate lets through starts the wait again. The wait is in the state file: a bank saved and loaded inside it goes on waiting, and issues its warning on the row an unbroken stream would. Under embargo both findings read the settled_frac of the rows the model has learned from, on the clock its weight has covered. The row’s own settled_frac counts the held rows’ clock too.

Both findings project a ceiling from the rows so far, and rows that come faster can beat it, so neither says the gate is unmet for good. At the rows’ spacing d and weight so far, the min_weight ceiling is 1 / (1 - 2 ** (-d / half_life)) times that weight. With a clock, d is known only from the rows, so the ceiling cannot be read from the spec before the rows arrive. A warning on a row of weight 0, or on rows too uneven to project (one row far heavier than the rest, or a stream whose weight is still its first row’s), gives no figure. A target the rows stopped carrying gets no figure where rows that each carried it would meet the floor, since its weight falls toward 0 once the rows stop carrying it.