1) Add interaction features
Here you’ll add interaction features for each pair of categorical features (ip, app, device, os, channel). The easiest way to iterate through the pairs of features is with itertools.combinations
. For each new column, join the values as strings with an underscore, so 13 and 47 would become "13_47"
. As you add the new columns to the dataset, be sure to label encode the values.
2) Number of events in the past six hours
The first feature you’ll be creating is the number of events from the same IP in the last six hours. It’s likely that someone who is visiting often will download the app.
Implement a function count_past_events
that takes a Series of click times (timestamps) and returns another Series with the number of events in the last six hours. Tip: The rolling
method is useful for this.
3) Features from future information
In the last exercise you created a feature that looked at past events. You could also make features that use information from events in the future. Should you use future events or not?
Run the following line after you’ve decided your answer.
4) Time since last event
Implement a function time_diff
that calculates the time since the last event in seconds from a Series of timestamps. This will be ran like so:
timedeltas = clicks.groupby('ip')['click_time'].transform(time_diff)
5) Number of previous app downloads
It’s likely that if a visitor downloaded an app previously, it’ll affect the likelihood they’ll download one again. Implement a function previous_attributions
that returns a Series with the number of times an app has been downloaded ('is_attributed' == 1
) before the current event.
6) Tree-based vs Neural Network Models
So far we’ve been using LightGBM, a tree-based model. Would these features we’ve generated work well for neural networks as well as tree-based models?
Run the following line after you’ve decided your answer.