Now that we have run an ets model on one category, we can construct some code to automate model construction over all of the categories.
In the process, we will also save some of the accuracy measures so that we can see how our models performed:
-
First, sort the dataframe by category, and then by year.
-
Then, initialize a new dataframe (onestep.df) that we will use to store the accuracy results for each moving window prediction of test and training data.
-
Then, process each of the groups, all of which have 14 time periods, as an iteration in a for loop.
-
For each iteration, extract a test and training dataframe.
-
Fit a simple exponential smoothed model for the training dataset.
-
Apply a model fit to the test dataset.
-
Apply the accuracy function in order to extract the validation statistics.
-
Store each of...