baybe.simulation.lookup.look_up_targets¶
- baybe.simulation.lookup.look_up_targets(queries: DataFrame, targets: Collection[Target], lookup: DataFrame | Callable | None, impute_mode: Literal['error', 'worst', 'best', 'mean', 'random', 'ignore'] = 'error')[source]¶
Add/fill target values in a dataframe using a lookup mechanism.
Note
This does not create a new dataframe but modifies
queries
in-place.- Parameters:
queries (
DataFrame
) – The dataframe to be modified. Its content must be compatible with the chosen lookup mechanism.targets (
Collection
[Target
]) – The targets whose values are to be looked up.lookup (
DataFrame
|Callable
|None
) –The lookup mechanism. Can be one of the following choices:
A dataframe mapping rows of
queries
to the corresponding target values. That is, it must contain the same columns asqueries
plus one additional column for each of the given target.A callable, providing target values for each row of
queries
.None
. Produces fake values for all targets.
impute_mode (
Literal
['error'
,'worst'
,'best'
,'mean'
,'random'
,'ignore'
]) –Specifies how a missing lookup will be handled. Only relevant for dataframe lookups. Can be one of the following choices:
"error"
: An error will be thrown."worst"
: Imputes the worst available value for each target."best"
: Imputes the best available value for each target."mean"
: Imputes the mean value for each target."random"
: A random row will be used for the lookup.
- Raises:
ValueError – If an unsupported lookup mechanism is provided.
- Return type:
Example
>>> import pandas as pd >>> from baybe.targets.numerical import NumericalTarget >>> from baybe.simulation.lookup import look_up_targets >>> >>> targets = [NumericalTarget("target", "MAX")] >>> df = pd.DataFrame({"x": [1, 2, 3]}) >>> lookup_df = pd.DataFrame({"x": [1, 2], "target": [10, 20]}) >>> look_up_targets(df, targets, lookup_df, impute_mode="mean") >>> print(df) x target 0 1 10.0 1 2 20.0 2 3 15.0