polars_online.target¶
- polars_online.target(column: str, *, name: str | None = None) Target[source]¶
Name a target column’s output fields after a name of your own.
Use it in a spec’s
targetswhen the column’s own name is not the name you want the fields to carry. For a target computed from its own row’s columns, make a column with Polars’with_columnsin the query before the bank, and for one computed from the rows after it, give a formula target (polars_online.ops).Parameters
columnThe column the model learns, read as it is. A target’s column used as a feature is refused, whatever its name.
nameThe name its output fields carry:
po.target("p", name="price")writespred_priceand the rest.None, the default, uses the column’s name, as a string target does, and so does anameequal to the column.
Returns
A
Targettable,{"column": column, "name": name}, withnameleft out when it is not given.Raises
TypeErrorcolumnornameis not a str, orrelative_toorrelativeis given: relative targets were removed, and the message says how to compute one as a column.ValueErrorcolumnornameis empty.
Examples
This code reads
dffrom Example data:spec = po.spec.ewridge( "m", targets=[po.target("y", name="price")], features=["x0"], half_life=50.0 ) print(po.target("y", name="price"), po.spec.output_fields(spec)[:2])
{'column': 'y', 'name': 'price'} ['pred_price', 'resid_price']See also
polars_online.ops, the window operators a formula target is built from.
Notes
Polars’ own spelling of a column under another name,
pl.col("p").alias("price"), is read intargetsas this same target. In the command line’s TOML the same target is a table:targets = ["ret_5m", { column = "p", name = "price" }].For a return, a log ratio (
(pl.col("p") / pl.col("mid")).log()) or a difference sits about zero, wherehit_ratereads its sign. A plain ratio sits about 1, where two positive numbers always agree in sign.