polars_online.ModelBank.audit¶
- ModelBank.audit(spec: str | int | None = None, group: str | Iterable[str | None] | None = None, *, table: Literal['columns', 'pairs', 'clock'] = 'columns', pooled: bool = False) DataFrame[source]¶
Return what an
auditspec counted, one row per column, pair of columns or clock.Use it to read the counts an
auditkeeps about the data itself: sentinel values, frozen feeds, few distinct values, heavy tails, duplicate columns and the clock’s spacing. For the findings drawn from them usecheck(), and for the statistics every spec keeps,describe().Parameters
specThe
auditspec to read, by name or by position (polars_online.spec.audit()). The default,None, reads the bank’s oneauditspec.groupThe group to read: one group key, as
groups()reports it, or a list of keys, withNonein the list for the null group. The default,None, reads every group. A key the bank has never seen gives no rows.tableWhich table to return:
"columns", the default, one row per (group, column);"pairs", one row per (group, pair of columns), for a spec built withpairs=True; or"clock", one row per group.pooledTruemerges the groups the frame covers into one audit, as if they were one stream, and drops thegroupcolumn. The counts merge exactly and the moments to rounding, and the counters past the cap and the digests approximately, aspolars_online.spec.audit()says. The default,False, gives a row per group.
Returns
A
DataFrameled byspec, as every reader of the bank’s is, with every count anInt64.table="columns"hasspec,groupandcolumn, then:rows_fed,null_count,nan_countThe rows read, then two kinds of value a model cannot learn from: the nulls, as Polars’
null_countcounts them, and the NaNs.pos_inf_count,neg_inf_count,beyond_bound_count,countThe other kinds, each counted apart (
beyond_bound_countis finite but past1e100in magnitude), andcount, the usable values. The six counts add up torows_fed.mean,std,skew,kurtosis,min,maxOver the usable values:
stdwithddof = 1, andskewand the excesskurtosisas scipy’s biased estimators. Null where undefined: no usable value, one, or no spread.median,mad,robust_zThe median and the median absolute deviation, exact while
n_uniqueis not null and from a t-digest past the cap (about 1% of the rows in rank), and the largest robust z,max(max - median, median - min) / (1.4826 mad).n_uniqueThe distinct usable values, as Polars’
n_uniquecounts them, with-0read as0. Null past the spec’sdistinct_cap.top_value,top_count,second_count,count_errorThe most repeated value, its count and the next value’s count. They are exact while
n_uniqueis, and past the cap each is at mostcount_errorshort of the truth, where a value not held has a count of at mostcount_error.longest_run,equal_prev,adjacent,equal_by_chancelongest_runis the longest run of one value on consecutive rows.equal_prevcounts the rows equal to the row before, out ofadjacent, the rows whose row before was usable too.equal_by_chanceissum p_v^2over the values’ sharesp_v: the share ofadjacentrows that independent rows would make equal, a lower bound past the cap.min_change,min_change_countThe smallest nonzero change
|x_t - x_(t-1)|between two consecutive usable rows (null before there is one), and how many changes sit at it. Two changes count as one size when they differ by no more than the rounding of one step of a grid,8 epsof the largest magnitude seen.check()’sfrozenweighsmin_change_countagainstequal_prev, the changes at 0.autocorr,unit_root_tautocorris the correlation of each usable row with the usable row before it.unit_root_tis the Dickey-Fuller statistic of that regression with a constant. It reads:above about -3 for a random walk;
about
-sqrt(n)for rows that do not persist;+inffor a fit with no residual and a slope of 1, such as a row counter;-inffor a fit with no residual and a slope below 1.
table="pairs"hasspec,group,column_a,column_b, and, over the rows where both are usable,count,corrandequal, the rows on which the two are equal.table="clock"has no rows for a spec without aclock. Its columns:spec,groupAs
groups()reports them.stepsThe number of steps between consecutive rows.
duplicatesHow many steps are 0.
gapsHow many steps are at or past
gap_cap(a clock requiresgap_cap).regularHow many steps are neither.
step_mean,step_std,step_cvThe regular steps’ mean, population standard deviation and coefficient of variation.
step_maxThe largest step of all.
On a temporal clock
step_mean,step_stdandstep_maxare aDurationin the clock column’s unit (milliseconds for aDate), on a number clock numbers in its units, and aFloat64before a chunk has said which.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.ValueErrorWhen:
specisNoneand the bank holds noauditspec, or several;specis not anauditspec;table="pairs"reads a spec built withoutpairs=True;tableis not"columns","pairs"or"clock".
Examples
This code reads
dffrom Example data:audit = po.spec.audit( "audit", columns=["x0", "x1"], clock="t", gap_cap=300.0, pairs=True ) bank = po.ModelBank([audit]) holes = pl.when(pl.col("t") < 10).then(None).otherwise(pl.col("x1")) bank.fit(df.with_columns(x1=holes)) # x1 null on the first 10 rows columns = bank.audit() # one row per (group, column) pairs = bank.audit(table="pairs") # one row per (group, pair) clock = bank.audit(table="clock") # one row per group print(columns.select("column", "rows_fed", "null_count", "count").rows()) print(pairs.select("column_a", "column_b", "count").rows()) print(clock.select("steps", "regular", "gaps").rows())
[('x0', 400, 0, 400), ('x1', 400, 10, 390)] [('x0', 'x1', 390)] [(399, 399, 0)]bank.audit(pooled=True)gives every group as one stream, with nogroupcolumn.See also
polars_online.spec.audit(), the spec and what it keeps.check(), the findings read from these tables.describe(), the statistics every spec keeps.
Notes
The counts are read from the state, so a bank loaded from its file reports what the bank that saved it would, and the stream’s chunking moves none of them.
A clock step is the time that passed between the two rows, uncapped: a model ages by at most
gap_capof it, and the audit counts all of it (across a session change under a numericsession_gap, that gap). A step back is refused, as for every spec. Withrestart_after_step_backeach one resets the audit’s steps instead (0resets at every one), andsummary()’sclock_backwardsandcheck()’sstep_backcount them.