LoslegenKostenlos loslegen

Train-test splits

In this exercise you are going to take the candy production dataset and split it into a train and a test set. Like you understood in the video exercise, the reason to do this is so that you can test the quality of your model fit when you are done.

The candy production data set has been loaded in for you as candy already and pyplot has been loaded in as plt.

Diese Übung ist Teil des Kurses

ARIMA Models in Python

Kurs anzeigen

Anleitung zur Übung

  • Split the time series into train and test sets by slicing with datetime indexes. Take the train set as everything up to the end of 2006 and the test set as everything from the start of 2007.
  • Make a pyplot axes using the subplots() function.
  • Use the DataFrame's .plot() method to plot the train and test sets on the axis ax.

Interaktive Übung

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

# Split the data into a train and test set
candy_train = candy.____
candy_test = candy.____

# Create an axis
fig, ax = ____

# Plot the train and test sets on the axis ax
candy_train.____(ax=____)
candy_test.____(ax=____)
plt.show()
Code bearbeiten und ausführen