LazyFrame.rheon.predict

LazyFrameRheonNamespace.predict(bank: ModelBank | str | PathLike[str], *, chunk_size: int | None = None, threads: int | None = None) → LazyFrame[source]

Predict a query’s rows from a bank as it stands, learning nothing.

Use it to serve a query’s rows, such as a file of new rows read with pl.scan_parquet, from a bank that has learned. For a frame in memory, use df.rheon.predict, and to predict rows and then learn them, use fit_predict().

Parameters

bank

The bank to predict from: a ModelBank, read as it stands each time the query runs, or the path of a saved state, read once, when the query is built. Predicting leaves a bank as it was, so a bank can be shared with the query. To pick up a newer state file, build the query again.

chunk_size

How many rows are predicted at a time: 100,000 by default. coef is written on each group’s last row in each chunk that is not skipped, whatever coef_every and max_rows_between_coefs say.

threads

How many threads to predict on, as ModelBank takes it. A bank given with a count is predicted from as a copy, so its own threads stay its own. Without one, a bank predicts on its own threads, and a path on the process’s.

Returns

A query holding the input’s rows with one output column per spec: what predict() gives each row, as the next row of its group’s stream. Target columns are optional, as they are for predict().

Raises

While the query is built:

FileNotFoundError

bank is a path that is not there.

ValueError

When:

  • the file is not a state this build loads (load());

  • bank is None;

  • chunk_size or threads is below 1.

ColumnNotFoundError

A column the bank reads, other than a target, is not in the query. It is a ValueError too.

WrongTypeError

A column the bank reads is of a type its role cannot take, such as a text feature, or a column is UInt128, which no frame can carry into the bank. It is both a TypeError and a ValueError.

TypeError

bank is neither a bank nor a path, or threads is not an integer.

OrderNotGuaranteedWarning

A warning, not an error: the query has a step whose row order Polars does not guarantee when it runs a query a chunk at a time, which the warning names.

While the query runs, a value the bank refuses (a null clock, a negative weight): under py-polars 1.x it arrives as Polars’ ComputeError carrying predict()’s message, and under 2.0 as its ValueError itself, since how a query wraps an error is Polars’ to change.

Examples

This code reads lf and later from Example data:

spec = rp.spec.ewridge("ridge", targets=["y"], features=["x0", "x1"], half_life=100.0)
bank = rp.ModelBank([spec])
bank.fit(lf)                              # learn df's 400 rows
bank.save("trained.state")
scored = later.rheon.predict("trained.state").collect()   # the next 400, unlearned
print(scored["ridge"].struct.field("pred_y").count(), bank.rows_fed)
400 400

See also