CommencerCommencer gratuitement

Define target variable

Here, you'll build a pandas pivot table with customers as rows, invoice months as columns, and number of invoice counts as values. You will use the last month's value as the target variable. The remaining variables can be used as the so-called lagged features in the model. You will not use them, but are highly encouraged to check if adding these variables will improve your model performance beyond what you'll see in the upcoming exercises.

The pandas and numpy libraries have been loaded as pd as np respectively. The online dataset has been imported for you.

Cet exercice fait partie du cours

Machine Learning for Marketing in Python

Afficher le cours

Instructions

  • Build a pivot table using the pivot_table() function counting invoices.
  • Store November 2011 sales data column name as a list.
  • Store the target value as Y.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Build a pivot table counting invoices for each customer monthly
cust_month_tx = pd.___(data=online, values='___',
                               index=['___'], columns=['___'],
                               aggfunc=pd.Series.nunique, fill_value=0)

# Store November 2011 data column name as a list
target = ['2011-___']

# Store target value as `Y`
Y = cust_month_tx[___]
Modifier et exécuter le code