polars_online¶
Streaming and online regression models for Polars.
One Rust core, run three ways, with the same numbers from each:
inside a Polars query:
lf.online.fit_predict(specs)is a query that feeds its rows through a bank when it runs, anddf.online.fit_predict(specs)fits a frame already in memory;ModelBank, a model bank fed one chunk at a time, whose memory grows with the models’ state and never with the number of rows that have passed. Handed a query, it reads the query a chunk at a time (ModelBank.fit_predict_batches(),ModelBank.fit());the
polars-onlinecommand line: Parquet, Arrow IPC, CSV or NDJSON in and out, with the state saved and resumed between runs (docs/RUNNER.md).
A spec names a model and the columns it reads (polars_online.spec).
Every way in takes a list of specs and writes one output column per spec. A
target is a column, a column under a name of its own (target()), or a
formula target, an expression over the window operators that looks ahead.
To fit a target computed from its own row’s columns, such as a price
against the mid, make the column with Polars’ with_columns in the query
before the bank.
The modules around the bank:
module |
what it does |
|---|---|
scores a bank’s output |
|
solves and diagnoses the Grams a bank exports |
|
transforms a query: targets whose values arrive late, series that tick at their own times, and exponentially weighted means, sums, rates, variances and quantiles looking back or ahead |
|
the window operators that |
|
repairs and reads correlation matrices |
|
simulates streams whose truth is known |
|
builds XGBoost’s and LightGBM’s training inputs from files or a query |
Errors follow one contract throughout, and each docstring says which part of it applies:
what went wrong |
the exception |
|---|---|
a file that cannot be read or written |
the |
a value that is refused: a spec parameter, a config key, what a column holds |
|
a column a spec reads that the frame does not have |
|
a spec’s output column that a scoring function’s frame does not have |
|
a wrong type |
|
a value out of range, or a combination of settings refused, that
once raised |
|
a spec name or position a bank does not have |
|
a bank fed from two threads at once |
|
Classes with two parents. A refusal that once raised a class the
table above no longer gives it raises a class of this library’s own that
inherits from both: the class the table gives, and the class it raised
before. WrongTypeError is a TypeError and a ValueError,
RefusedValueError a ValueError and a TypeError, and
OutputColumnNotFoundError a ColumnNotFoundError and a
KeyError. So a handler written for either class keeps catching the
refusal, and new code can catch the class that names the problem. Changing
the class outright would let such a refusal slip past an except that
catches it today.
The older parent is dropped at the next major version: catch TypeError,
ValueError and ColumnNotFoundError respectively.
Inside a running Polars query the same exception arrives wrapped in
Polars’ ComputeError under py-polars 1.x, carrying its message, and as
itself under 2.0: how a query wraps an error is Polars’ to change. A run
the bank refuses, or one abandoned before its last row, never replaces a
state file. A refused chunk leaves a bank
as it was, apart from the two cases ModelBank.fit_predict() names.
See also
The feature index, every feature of the library with a line each.
The highlights page, four use cases run end to end.
The model bank¶
Run a model bank over a query, a frame or chunks you feed it, and turn the output column it adds into columns, or hand it over as Arrow. Give a target’s output fields a name of your own, or write a target as a formula that looks ahead. Read the compiled extension’s version, the version of the state files it writes, and the number of threads a bank runs on.
A set of models fitted together over the same rows, fed one chunk at a time. |
|
Add each spec’s output column to a query’s or a frame’s rows, learning them. |
|
Predict a query’s or a frame’s rows from a bank as it stands, learning nothing. |
|
Turn each spec’s output column in a query or a frame into one column per field. |
|
Name a target column’s output fields after a name of your own. |
|
A target column under a name of its own, written as a table. |
|
A formula target, written as a table. |
|
One spec’s output column, as an Arrow struct array a consumer reads once. |
|
The number of threads a bank given this |
|
The version of the compiled extension, which equals |
|
The version of the state file’s layout that this build writes. |
Errors¶
This library’s own errors, each also a subclass of the built-in or Polars class a handler may already catch.
The error raised when a column a call reads is not in its input. |
|
The error raised when a spec’s output column is not in the frame a scoring function reads. |
|
The error raised for a value of the wrong type where |
|
The error raised for a refused value where |
Warnings¶
PolarsOnlineWarning, and the warnings the library issues, each a subclass
of it.
The base class of every warning this library issues. |
|
A warning that a model is not ready, or may never become ready. |
|
A warning that Polars may change the row order of a query a bank or a window run reads. |
|
A warning that a query whose source is written in Python may give its rows only once. |
|
A warning that a renamed name was used by its old spelling. |
|
A warning that a part of the API not yet promised to stay the same was used. |