rheon.target

rheon.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 targets when 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_columns in the query before the bank, and for one computed from the rows after it, give a formula target (rheon.polars.ops).

Parameters

column

The column the model learns, read as it is. A target’s column used as a feature is refused, whatever its name.

name

The name its output fields carry: rp.target("p", name="price") writes pred_price and the rest. None, the default, uses the column’s name, as a string target does, and so does a name equal to the column.

Returns

A Target table, {"column": column, "name": name}, with name left out when it is not given.

Raises

TypeError

column or name is not a str, or relative_to or relative is given: relative targets were removed, and the message says how to compute one as a column.

ValueError

column or name is empty.

Examples

This code reads df from Example data:

spec = rp.spec.ewridge(
    "m", targets=[rp.target("y", name="price")], features=["x0"], half_life=50.0
)
print(rp.target("y", name="price"), rp.spec.output_fields(spec)[:2])
{'column': 'y', 'name': 'price'} ['pred_price', 'resid_price']

See also

Notes

Polars’ own spelling of a column under another name, pl.col("p").alias("price"), is read in targets as 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, where hit_rate reads its sign. A plain ratio sits about 1, where two positive numbers always agree in sign.