LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Machine Learning for Marketing in Python

Kurs anzeigen

Anleitung zur Übung

  • 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.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# 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[___]
Code bearbeiten und ausführen