Recency feature
A recency feature says how recent a certain event has happened in the past. The more recent an event has occurred, the closer its recency will be to 1. If a new and previously unseen case occurs, its recency will be 0. Such features helps detecting anomalous behavior. In the video, you learned how to create a recency feature based on a categorical feature. You're provided with the dataset trans
containing transactions made by Alice and Bob. You're going to create a recency feature called rec_channel
based on the column channel_cd
.
The zoo
and dplyr
packages are loaded for you. The frequency feature freq_channel
from the previous exercise was added to the dataset trans
. trans$timestamp
are converted to hourly format, and gamma
has been set for you to -log(0.01)/90
.
This exercise is part of the course
Fraud Detection in R
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create the recency function
recency_fun <- function(t, gamma, channel_cd, freq_channel) {
n_t <- length(t)
# If the channel has never been used, return 0
if (freq_channel[n_t] == ___) {
return(___)
}
}