initialWindow: the initial number of consecutive values in each training set sample.The three parameters for this type of splitting are: You can additionally specify if the results should be stored as a list with list = TRUE or list = FALSE.Īdditionally, caret contains a function called createTimeSlices that can create the indices for this type of splitting. The values you see in the createResample function are the data and the number of partitions to create, in this case 2. Points(density(x), type = "l", col = 4)ĬreateTimeSlices(1:9, 5, 1, fixedWindow = FALSE)ĬreateTimeSlices(1:9, 5, 1, fixedWindow = TRUE)ĬreateTimeSlices(1:9, 5, 3, fixedWindow = TRUE)ĬreateTimeSlices(1:9, 5, 3, fixedWindow = FALSE) InA <- createDataPartition(x, list = FALSE) Here's an example of its usage: data(oil) So you'll probably want to use createResample. Using the package caret, createResample can be used to make simple bootstrap samples and createFolds can be used to generate balanced cross–validation groupings from a set of data. Hyndman on cross-validation for time-seriesįirst, let me give you a scholarly article on the topic. Lastly, the 12-month horizon in this example is not a true multi-period forecasting as Hyndman does it in his examples. It merely trains a model to best explain the variation in unemployment (which also in this case is a stationary time-series creating all sorts of issues in modelling process) based on predictor variables at the same economic report dates. Next, this example is only descriptive statistics and not predictive (forecasting) because the data we want to forecast (unemploy) is not lagged correctly. Unemployment data may be two months behind the other indicators in terms of release date, which would then introduce a model bias in Shambho's example. In this case, the economics data set has aligned data at their economic reporting dates and not their release date, which is never the case in real live applications (economic data points have different time stamps). The problem with time-series data is that look-ahead bias is easy if one is not careful. So in order not to misguide future readers that want to use the caret package for predictive modelling on time-series (and here I do not mean autoregressive models), I want to highlight a few things. Shambho's answer provides decent example of how to use the caret package with TimeSlices, however, it can be misleading in terms of modelling technique. The final value used for the model was ncomp = 1. RMSE was used to select the optimal model using the smallest value. Resampling results across tuning parameters: Resampling: Rolling Forecasting Origin Resampling (12 held-out with a fixed window) Step 1: Creating the timeSlices for the index of the data: timeSlices str(timeSlices,max.level = 1)įor ease of understanding, I am saving them in separate variable: trainSlices myTimeControl Step 0: Setting up the data and trainControl:(from your question) library(caret) However, here is how to use createTimeSlices for splitting the data and then using it for training and testing a model. Note that the original question that you have posted, takes care of the timeSlicing, and you don't have to create timeSlices by hand.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |