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, usedf.rheon.predict, and to predict rows and then learn them, usefit_predict().Parameters
bankThe 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_sizeHow many rows are predicted at a time: 100,000 by default.
coefis written on each group’s last row in each chunk that is not skipped, whatevercoef_everyandmax_rows_between_coefssay.threadsHow many threads to predict on, as
ModelBanktakes 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 forpredict().Raises
While the query is built:
FileNotFoundErrorbankis a path that is not there.ValueErrorWhen:
the file is not a state this build loads (
load());bankisNone;chunk_sizeorthreadsis below 1.
ColumnNotFoundErrorA column the bank reads, other than a target, is not in the query. It is a
ValueErrortoo.WrongTypeErrorA 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 aTypeErrorand aValueError.TypeErrorbankis neither a bank nor a path, orthreadsis not an integer.OrderNotGuaranteedWarningA 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’
ComputeErrorcarryingpredict()’s message, and under 2.0 as itsValueErroritself, since how a query wraps an error is Polars’ to change.Examples
This code reads
lfandlaterfrom 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
predict(), which this runs over each chunk, and the fields it gives.fit_predict(), which learns each row after predicting it.rheon.polars.predict(), this method as a function a type checker can see.