Session Ready
Exercise

Frequency feature for one account

A frequency feature counts how frequently a certain event has happened in the past. Creating such features helps detecting anomalous behavior. In the video, you learned how to create a frequency feature based on a categorical feature.

You're now provided with transactional data from Bob. One of the columns is called channel_cd which indicates the payment channel that Bob used to book each of his transactions. You'll be creating a frequency feature called freq_channel based on the column channel_cd using the function rollapply(). You can use ?rollaply in the console to see the function documentation.

The dataset trans_Bob, the zoo and dplyr packages are loaded in your workspace.

Instructions
100 XP
  • Write a function frequency_fun() which takes steps and channel as inputs, counts the number of steps, and sums how often the latest channel has been used in the past.
  • Create the feature freq_channel by using the function rollapply on the transfer_id column. The feature should count how often a particular channel_cd has been used before.
  • Print the features channel_cd, freq_channel and fraud_flag. Inspect the newly created feature.