ComeçarComece de graça

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.

Este exercício faz parte do curso

Fraud Detection in R

Ver curso

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# 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(___)
  }
}
Editar e executar o código