2
$\begingroup$

I have a time series that I am trying to model using a Random Forest of regression trees as part of the scikit-learn ensemble library. In order to prepare the model for forecasting, I have included as features the five previous hourly target values in the training set, among other features:

+-----+-----+-----+-----+-----+------------+
| n-1 | n-2 | n-3 | n-4 | n-5 |          y |
+-----+-----+-----+-----+-----+------------+
| 10  | 11  | 4   | 36  |  18 |         15 |
| 15  | 10  | 11  | 4   |  36 |          4 |
|  4  | 15  | 10  | 11  |   4 |         21 |
| 21  |  4  | 15  | 10  |  11 |          9 |
|  9  | 21  |  4  | 15  |  10 |         55 |
+-----+-----+-----+-----+-----+------------+

However, when I use the model to predict future values (say, 5 hours into the future), I face a similar imputation question: how should I fill the null values?

+-----+-----+-----+-----+-----+------------+
| n-1 | n-2 | n-3 | n-4 | n-5 |       yhat |
+-----+-----+-----+-----+-----+------------+
| 11  | 31  | 42  |  6  |  12 |         15 |
| NA  | 11  | 31  | 42  |   6 |          4 |
| NA  | NA  | 11  | 31  |  42 |         21 |
| NA  | NA  | NA  | 11  |  31 |          9 |
| NA  | NA  | NA  | NA  |  11 |         55 |
+-----+-----+-----+-----+-----+------------+
  1. One idea is to predict one row at a time, and then use the predictions to fill the values in the subsequent row. One reason this might be bad is that the prediction values are probably off themselves, and so I am just compounding (potentially) my errors as I get further into the future (but which may be inevitable anyway).

  2. The other idea is, if only "n-1" is missing, just fill it with "n-2". But there will be rows for which all "n-1" to "n-5" are missing. In that case, I suppose they could just be filled with whichever were the most recent "n-1" to "n-5" values from the recent past.

Is one (or some strategy not considered) to be preferred?

$\endgroup$
  • $\begingroup$ I was facing similar challenge when i tried using auto.arima in forecast package. This uses ARIMA with external regressors. I had the same idea as that of yours for first method you pointed. It worked quite well with a low Mean Absolute Percentage Error than if i did not include it. stats.stackexchange.com/questions/189983/… $\endgroup$ – Enthusiast Jan 13 '16 at 6:46
0
$\begingroup$
  • You will have a 'burn-in' period for the first time points before t1, when you generate descriptors' looking t1 time backwards. Also if you forecast interval is t2, you will have a 'burn-out' period t2 of the the last time points.

  • To build a fair RF model you will probably need 150-5000 samples depending on how difficult the task is. Then burning some few time points in either end does not matter much. If your model only has ~30 time points, strongly consider other forecasting priciples: linear regression, auto-regresion, ARIMA etc.

  • I don't think your future prediction performance will improve by imputing NAs.

  • Bonus advice: If your time series is not stationary, consider computing the first derivative (change/time) and model this instead. Otherwise your model will end up forecasting the next value as something very close to the last value. Such predictions are trivial and often useless.

disclaimer: I'm only a "time series hobbyist" :)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.