4.1.3.4 Create/Add New Feature
You can create new features and add to the existing dataframe.
Create New Feature
%python-pgx
import pandas as pd
def custom_feature(X, key_var='EVENT_ID'):
V = abs(X["TOTAL_DEPOSIT_AMOUNT"].fillna(0)+X["TOTAL_WITHDRAWAL_AMOUNT"].fillna(0))
return pd.DataFrame({key_var : X[key_var], 'AVG_TRXN_PER_CT' : V})
df = custom_feature(evented_data_pdf)
Most scenarios use simple parameters which trigger an alert when the parameter value is greater than a threshold. However, some scenarios employ more complex parameters, which trigger an alert only when the parameter value is within a range. Such complex parameters e.g, Min_Percentage in the Rapid Movement of Funds scenario have to be appropriately transformed before the default scenario tuning methodology can be applied. For more information, see the Handling Complex Parameters section.
View Newly Created Feature
%python-pgx
z.show(df.head())
Add New Feature with Existing Dataframe
A new feature will be added to the existing dataframe, so expression should also be updated. Use parameter tunable_parameters to update the existing expressions for the tunable parameters. Based on the expression, strata will be find out.
If it is None, then it would use the same expression which would have set in the scenario execution notebook.
%python-pgx
asc.add_to_event_dataset(df_list=[df])
Get Updated Dataframe
%python-pgx
evented_data_pdf = asc.get_event_dataset()
z.show(evented_data_pdf.head())