HomeGuidesRecipesChangelog
Guides

Target Function: Extra Columns

In some cases, the target function may require access to columns that were not used during model training. For example, a basket id column might be necessary to group transactions belonging to the same basket. Although such columns are not meaningful for training and are therefore excluded from the training process, they can still be provided at inference time using extra columns. In this article, we’ll show how to access extra columns in your target function.

First, you need to define access to the additional columns. To learn how to do this, refer to the Defining extra columns section.
Once configured, these columns can be retrieved using the .extra parameter on the data source.

The example below demonstrates how to access basket_id column that was not used in a model training but was added as an extra column from the transactions data source.

def target_fn(_history: Events, future: Events, _entity: Attributes, _ctx: Dict) -> np.ndarray:
    target_window_days = 21
    if has_incomplete_training_window(ctx=_ctx, required_days=target_window_days):
      return None
    
    transactions = future["transactions"]
		# access basket id extra column values
		basket_id_values = transactions.extra["basket_id"]