rheon.polars.ModelBank.check¶
- ModelBank.check(spec: str | int | None = None, group: str | Iterable[str | None] | None = None) DataFrame[source]¶
Return findings about the data each model was fed, one row per problem, the worst first.
Run it after a first pass over the data, before trusting a fit: it names features null on many rows, constant or collinear features, leakage, a clock that steps back, models that never warmed up, and more. To find what no model keeps, such as sentinel values or a frozen feed, put an
rheon.spec.audit()in the bank, and read its counts withaudit().Parameters
specThe spec to check, by name or by position. The default,
None, checks every spec.groupThe group to check: one group key, as
groups()reports it, or a list of keys, withNonein the list for the null group. The default,None, checks every group. A key the bank has never seen gives no rows.
Returns
A
DataFramewith one row per finding, in severity order, then spec order, thengroups()’ order. A bank that has seen no rows gives an empty frame. The columns:severityerror(the model cannot learn),warning(the fit is unreliable) orinfo: anEnumin that order, worst first.codeWhich check found it: a short name that stays the same across releases, one of the codes listed under Returns. It is a
String, not anEnumasseverityis. A minor release may add a check, and anEnum’s categories are part of its dtype, so a new code would change the column’s type under code that pins it.spec,groupThe spec and group, as
summary()names them.groupis null fornot_checked, which is about the spec as a whole.columnThe input column the finding is about, where there is one.
value,thresholdThe measured number, and the line it crossed. Null for
withheldandnot_checked.messageWhat is wrong and, for most codes, what to do. It ends with a link to the code’s section of docs/DATA-QUALITY.md, which shows what the problem does to each model and how to fix it with Polars, before the bank, in a program that runs.
The codes every spec can find:
code
severity
fires when
nothing_learnederror
a model was fed rows and learned from none; the column null most often is named
missingwarning
a feature or the weight column is null, NaN, infinite or past 1e100 on 10% of the rows or more, each of them skipped; an error at 100%, and information for a target missing on half the rows or more, since sparse targets are a design, not a fault
few_learnedwarning
more than half the rows were skipped for a missing feature or weight, whichever columns caused it
constanterror, warning
a target (error) or a feature (warning) took one value on every row
level_over_spreadwarning, info
a feature’s
|mean| / stdpasses the limit of a model that does not center it (Notes); information past 1e6 for the models that doscales_apartwarning
the widest feature’s spread over the narrowest’s passes the limit of a model that takes one step for every column (Notes)
ridge_shrinkswarning
ewridge,huberorquantilewithoutstandardize, atridge_scale="mean"(the default): the smallest ridge is a quarter of a feature’s variance or more, so it takes a fifth of that coefficientcollinearwarning
the largest variance inflation factor, or the condition index of the design the model solves, over the features passes 30, from the Gram of an
ewridgeorlasso(information for anew_cov). A model with an intercept centers, so its index is the features’ correlation matrix’s,sqrt(d_max / d_min); one fitted through the origin reads Belsley’s uncentered index (rheon.gram.condition())leakagewarning
a feature correlates with a target at 0.9999 or more, from the Gram or a
marginal: it contains the target, both are one random walk, or the relation is nearly exact (a correlation of 0.9999 is an R² of 0.9998 for that feature alone)step_backwarning
the clock stepped back, a reset or a late row under
restart_after_step_backresetsinfo
a model reset at a
session_gap = "reset"or a step backfew_rowswarning
a regression learned from fewer rows than it has coefficients
group_sizesinfo
the largest group learned from 100 times the rows of the smallest or more
never_settledwarning
a model has seen less than one half-life of clock (
settled_fracbelow 0.5)below_min_weightwarning
the weight a model’s
weight_sumtops out at (weight_sum_settled) is below the spec’smin_weight, so its predictions stay nullwithheldwarning
a model’s last row had its predictions withheld, with the reason
low_supportwarning
the smallest coefficient’s data share is below 0.5, the command line’s readiness line; not repeated for a column already found constant, collinear or shrunk by the ridge
solve_failureswarning, info
a model’s
solve_failures()count is above 0 (warning); forlasso, more than 10 (information)not_checkedinfo
numpy is not installed, so
collinearandleakagewere not checked on a spec with a Gram and a group to read it from; said only of a spec with a group to checkAn
auditknows no roles, so its column’smissingshare is information (an error at every row), and itsconstanta warning.step_backandresetsare read from itssummary()as for any spec. Its own codes, read fromaudit():code
severity
fires when
sentinelwarning, info
a column holds
+inf,-infor a value past1e100(warning); holds NaN, not null (information); or one value is 1% of its usable rows or more, at least 5 times as often as any other can be (warning), unless the column has 10 values or fewer or is frozenfrozenwarning
the rows equal to the row before, less those the column’s value frequencies give by chance, outnumber the changes at its smallest step by five standard errors,
(repeats - chance - at_step) / sqrt(repeats + at_step), where that step is less than half the column’s moves: an atom of changes at zero, which a stale feed adds and a column on a coarse grid (an hour, a regime, a price in ticks) does not showfew_valuesinfo
10 distinct values or fewer over 100 usable rows or more
random_walkwarning
the Dickey-Fuller statistic is above -3.5 (the 1% critical value is -3.43) over 100 pairs of rows or more
heavy_tailsinfo
an excess kurtosis of 5 or more, or a value 10 robust standard deviations or more from the median;
valueis the robust z where it fired, the kurtosis otherwise, each beside its own thresholdduplicatewarning
with
pairs=True, two columns correlate at 0.999 or moreduplicate_stampsinfo
a row shares the clock of the row before
gapsinfo
a step reaches
gap_capirregular_clockinfo
the regular steps’ coefficient of variation is 0.5 or more
Raises
KeyErrorspecis a name the bank does not have.IndexErrorspecis a position the bank does not have.TypeErrorgroupis not a str, a list of them withNoneallowed, orNone.
Examples
This code reads
dffrom Example data:spec = rp.spec.ewridge( "ridge", targets=["y"], features=["x0", "x1", "x2"], half_life=100.0 ) bank = rp.ModelBank([spec]) bank.fit(df.with_columns(x2=pl.lit(1.0))) # x2 made constant problems = bank.check() # the worst first print(problems.select("severity", "code", "column").rows())
[('warning', 'constant', 'x2')]To keep only what needs action, drop the information:
problems.filter(pl.col("severity") != "info").See also
Data quality, each problem, what it does to each model, and its fix.
summary(),describe()andaudit(), the counts the findings are read from.rheon.spec.audit(), the spec that keeps what no model keeps.
Notes
checkreads only what the bank keeps anyway:summary(),describe(),solve_failures(),last_row(), andgram(),marginal()oraudit()where the spec has one. So it adds no work to the run, a bank loaded from its file gives the same findings as the bank that saved it, and the input’s chunking moves none of them.Every threshold was measured before it shipped, for how often it finds a planted problem and how often it fires on clean data. How the checks work gives the clean streams, the planted problems and the numbers each line was set from.
level_over_spreadandscales_apartread a limit for each model: the largest value at which its out-of-sample R² fell by no more than 0.05, at half-lives of 20, 200 and infinite (forrls’s level limit, at half-lives of 200, 2,000 and infinite, over 2,000 and 20,000 rows).model
level limit
spread-ratio limit
ftrl0.5
1.5
kalman,standardize=False2
2
sgd,standardize=False3
3
pa,standardize=False3
2
rls0.9 sqrt(W / delta_left)30
rls’s level limit is read from the summary. A level lowers its accuracy only through the part of its priordelta Iit still holds,delta_left = delta (1 - settled_frac)(all ofdeltawithout decay), set against the weight its fit holds,W(settled_frac * weight_sum_settled, orweight_sumwithout decay). So a decayingrlsthat has forgotten its prior is told nothing, at any level. The models that center their features (ewridge,lasso,huber,quantile, andkalman,sgdandpaat their defaultstandardize=True) lost nothing at a level of 1e14 times the spread. Nor did they at spreads 1e8 apart, except where a narrow feature met an unstandardized ridge, whichridge_shrinksfinds.A level or a spread ratio counts only when it is five standard errors from what a centered column, or two of equal spread, would show by chance in that many rows. The Gram’s checks wait for ten Kish rows a coefficient. Both guards keep a small group quiet.
What it cannot see.
describe()keeps every row’s moments undecayed, so a feature that drifted slowly can sit far above its recent spread without showing as a level. The Gram’s checks cover the three models whose Gram the bank exports (gram()), andleakagealso reads amarginal. Anauditmeasures what no model keeps: sentinel values counted apart from nulls, a frozen feed, a column of few distinct values, a level fed as a feature, heavy tails, duplicate columns, and the clock’s duplicate stamps, gaps and irregular spacing. Without one in the bank, nothing is said about them. A group a spec closes (group_close) leaves the bank with its model, so nothing is said about it either: the findings cover the groups still open. Anauditrefusesgroup_closefor that reason.