Controlling cutoff times in a label search¶
The start time of the labeling process is known as the first cutoff time. You need data that exists before the first cutoff time to build features. You can use
minimum_data in a label search to directly define the first cutoff time or the amount of data needed before the first cutoff time. Similarly, you can use
maximum_data to directly define the last cutoff time. These parameters let you control when the labeling process starts and finishes.
Labeling customer transactions¶
For example, suppose you have customer transactions from the first quarter of 2021.
import composeml as cp transactions.head()
You want to calculate the total amount that customers spent over two weeks only for February. Start by defining a labeling function that sums up the transaction amount. Then, create a label maker that will label data over two weeks using the transaction time.
def total_amount(ds): return ds.amount.sum() lm = cp.LabelMaker( labeling_function=total_amount, time_index='transaction_time', target_dataframe_index='customer_id', window_size='14d', )
Defining the first and last cutoff time¶
Now, you can use
minimum_data in the label search to directly set the 1st of February as the first cutoff time. Since you are labeling data over two weeks, you can define the last cutoff time as the 15th.
lt = lm.search( df=transactions.sort_values('transaction_time'), num_examples_per_instance=-1, minimum_data='2021-02-01', maximum_data='2021-02-15', drop_empty=False, verbose=False, ) lt
Changing the first cutoff time for each customer¶
Suppose you have a lookup table that contains the dates when customers signed up and created their accounts. Now, you are interested in calculating the total amount that customers spent over two weeks only after creating an account.
customer_id 1 2021-01-10 2 2021-02-12 3 2021-01-23 4 2021-02-13 5 2021-01-24 Name: created_account, dtype: datetime64[ns]
You can use the column of sign up dates directly as the first cutoff times in the labeling process. Each customer should only have one cutoff time.
lt = lm.search( df=transactions.sort_values('transaction_time'), num_examples_per_instance=-1, minimum_data=created_account, drop_empty=False, verbose=False, ) lt.head(10)
For more details on labeling data over specific periods, you can look at the guide on generating data slices.