Skip to content

Instantly share code, notes, and snippets.

@gvyshnya
Last active April 19, 2021 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gvyshnya/958790c7eef1a4557772f9b4fd29bb85 to your computer and use it in GitHub Desktop.
Save gvyshnya/958790c7eef1a4557772f9b4fd29bb85 to your computer and use it in GitHub Desktop.
Adding groupby aggregate features with featurewiz
### create groupby aggregates of the following numerics
agg_nums = ['cont1','cont3']
groupby_vars = ['cat2','cat4']
train_add, test_add = FW.FE_add_groupby_features_aggregated_to_dataframe(train[agg_nums+groupby_vars],
agg_types=['mean','std'],
groupby_columns=groupby_vars,
ignore_variables=[] , test=test[agg_nums+groupby_vars])
# join the dataframes with the aggregated features to the main training and testing set dataframes
train_copy = train.join(train_add.drop(groupby_vars+agg_nums, axis=1))
test_copy = test.join(test_add.drop(groupby_vars+agg_nums, axis=1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment