I've some demand data, for which I wish to judge what will be the direction in the forecast period (Up/Down). What will be a best ML method to do this? Currently I'm using the data given below -

9/4/2016 241 9/11/2016 233 9/18/2016 226 9/25/2016 282 10/2/2016 291 10/9/2016 282 10/16/2016 308 10/23/2016 291 10/30/2016 268 11/6/2016 262 11/13/2016 273 11/20/2016 262 11/27/2016 309 12/4/2016 317 12/11/2016 331 12/18/2016 382 12/25/2016 358 1/1/2017 359 1/8/2017 342 1/15/2017 332 1/22/2017 324 1/29/2017 298 2/5/2017 283 2/12/2017 274 2/19/2017 278 2/26/2017 245 3/5/2017 214 3/12/2017 217 3/19/2017 204 4/16/2017 204 4/23/2017 187 4/30/2017 203 5/7/2017 198 5/14/2017 211 5/21/2017 186 5/28/2017 176 6/4/2017 183 6/11/2017 180 6/18/2017 177 6/25/2017 157 7/2/2017 179 7/9/2017 191

I'm using 'forecastHybrid' package in R with the following code, but unfortunately the forecasts I'm getting based on last observation only (i.e. 191), which doesn't seem to be correct.

Will any other model be relevant here, i.e. SVM, RF etc. Any specific guidance/code in R will be much appreciated.

mod1 <- hybridModel(t) fc1 <- forecast(mod1) fc1


2 Answers 2


Well there are several approaches to this:

You could use the data as is and simply try different time series models as you already did. You could also try a random forest or gradient bossted trees but I think the number of observations is to low for them to produce good results.Still, whether a method works well or not can only be answered empirically. Thus, just go for it ( I would recommend to use the caret package)

Another approach would be to change the target variables and to generate a dummy indicating whether demand increased or decreased. You can again use any model that can handle a binary target variable (regression/logistic regression/tree based method/naive bayes and so on)

Moreover, I would suggest that you should spend some time on feature engeneering. You can easily add holidays...time before/after holidays and so on. You can use any expert knowledge or simply common sense to come with new features.

I hope this helps.

  • $\begingroup$ Many thanks for your help and guidance. Can you please shed some light on feature engineering? I was trying an SVM model changing the target variable as - whether the demand is up or down, but that's also giving some errors while fitting SVM. Little more on this will be of great help. Apologies for asking again as I'm a newbie to Machine learning and on the path of learning. $\endgroup$
    – drsb24
    Aug 17, 2017 at 7:56
  • $\begingroup$ Sure. I would start easy and not go into svm's just yet. Use a simple OLS and try some new features. If you use svm you need to standardize the data first. Well the first and easy feature is to generate a holiday dummy. A variable that takes the value of one if a given date was holiday and zero otherwise. Christmas is very special in the case of demand. People are shopping heavily before christmas hence you could generate a metric variable that simply counts the days untill christmas from a given start date..lets say starting in November. $\endgroup$
    – JustMe
    Aug 18, 2017 at 8:25
  • $\begingroup$ Then I would generate a Dummy indicating the first 2 Weeks after Christmas because generally this is period with low demand. I dont know your specific usecase but maybe you have some info on special marketing events and stuff like that which you could also encode using a dummy. Another important feature might be the weather so you would need to get some weather data predictions. Of course you need use your target variable lagged by x periods if you dont rely on auto time series models. $\endgroup$
    – JustMe
    Aug 18, 2017 at 8:26
  • $\begingroup$ with respect to SVM: Use a linear kernel first before going nonlinear. You need to rescale your features to be on the same scale using a mean/std dev scaler or a min/max scaler. Just search for standardizing features. All this can be done in caret quite easily. If you want help on specific error massanges...well you would need to tell me the exact errormassage :) $\endgroup$
    – JustMe
    Aug 18, 2017 at 8:28

The answer is DOWN based upon the equation enter image description here

I don't write r code ....

enter image description here


When dealing with a single time series there are a number of possible features/elements/items of a useful model. AUTOBOX a piece of software that I have helped to develop pursues a broad strategy of item selection. First and primary is should memory be used OR should dummy predictors ( level shifts , time trends , seasonal pulses , other time-oriented fixed effects )be used OR should thee be some combination. Secondly are their any anomalies/pulses that need to be treated/adjusted ? Thirdly is there evidence of non-constant error variance and if so should we transform the data OR use weighted least squares to render the model error variance to be homogeneous ALL while validating the assumption that parameters have not varied over time.

Upon running heuristics/model diagnostics in an Exploratory Data Manner , the program iteratively assesses significance by optimizing the sequence of approaches culminating in a possible useful model. The model can be "understood" by examining the ultimate design matrix which was ferreted out by the diagnostics. Here it is .enter image description here .

The model suggests two time trends 1-18 and 19-38 both clearly visually visually supportable. The model suggests a level shift i.e. an intercept change at or about period 26 The model suggests an unusual value/pulse at period 16 The model suggests less randomness in the residuals at or about period 17

The freely available parametric software in R does not pursue sufficient global strategies i.e. testing for possible non-gaussian violations and providing remedies often ( nearly always in my biased opinion !) mis-analyzes data. 1 Corinthians 13:11 has words to this effect. If you search in my previous postings on se you will get further examples of results like this.

The human eye is often a great modelling tool and the question is can software proxy the clear eye in identifying meaningful structure. In this case I would have to say a definite yes. Ad hoc approaches as suggested by others in an attempt to do feature engineering is time-wasting and largely unproductive. This is not to say that holiday effects and other calendar effects should not be used . They should ! See my most recent post for an example of that ARIMA model has trouble forecasting next month . Other posts illuminate how holiday effects can be automatically formed and you might also look at http://www.autobox.com/cms/index.php/afs-university/intro-to-forecasting/doc_download/53-capabilities-presentation .. slide 49-68 .

  • $\begingroup$ Many thanks, but apologies, can you please explain the above model, I mean how do you arrive? Which software and which model has been used in this? If you can please elaborate, I'll be really grateful and hence can proceed accordingly. $\endgroup$
    – drsb24
    Aug 11, 2017 at 4:18
  • $\begingroup$ It has been a while . Do you still have questions ? $\endgroup$
    – IrishStat
    Aug 20, 2017 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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