2.3 Practical Exercises for Chapter 2
These exercises will help you practice feature engineering techniques specifically for classification and regression models. Each exercise comes with a solution that includes code for guidance.
Exercise 1: Calculate Recency for Each Customer
In a retail dataset, calculate the Recency feature for each customer, which represents the number of days since their last purchase. Use this feature to predict customer engagement.
Load the dataset.
Convert the PurchaseDate column to datetime.
Calculate Recency as the number of days since the most recent purchase.
data = {'CustomerID': [1, 2, 1, 3, 2],
'PurchaseDate': ['2023-07-01', '2023-07-10', '2023-07-15', '2023-07-20', '2023-08-01' ...