5
$\begingroup$

Issue: Cannot forecast sales accurately using quantile regression in R. I am using rq function from "quantreg" package which is giving me warning "Result might have Non unique solutions"

Aim: I am trying to forecast hourly sales of a store using quantile regression.

Below are the columns in my source table for forecasting.

  • transaction_date : sales date (input)
  • hr1 to hr24 : column with hourly sales info. (24 columns) (input)
  • totala : total of 24 column hr1 to hr24 (not using currently)
  • location, department, sales_type: forecasting will be done for each location, sales_type and department. (used to select data)
  • f1 to f24 : columns I want to forecast for each hour (24 columns) (output)

Packages Used: forecast, quantreg, Metrics

Code: I have extracted date features from transaction_date eg. weekend, week of month and also holidays (1 if it is holiday 0 for regular days).

attach(train_data) 
Y <- cbind(hr) 
X <- cbind(transation_date, Years, Months, Days, WeekDay, WeekofYear, Weekend, WeekofMonth, holidays) 

quantreg.all <- rq(Y ~ X, tau = seq(0.05, 0.95, by = 0.05))
prediction_train <- data.frame(predict(quantreg.all))

I have 19 models in prediction_train for each tau from 0.05 to 0.95, I select best model based on rmse value and than forecast using that tau.

rmse(actual, predicted)

transaction_date is Date type, quantreg.all is rqs class and rest are numeric.

Note: Stores are not open 24 hours, hence many hour columns will be 0 (time when store was close). Currently for most of such hours rq is predicting 0 or some negative values.

Weather does not have major impact on sales.

$\endgroup$
2
  • $\begingroup$ What is the actual problem? That you're predictions aren't very accurate? Or that you're getting the warning from rq? $\endgroup$
    – scribbles
    Commented Aug 12, 2015 at 20:55
  • $\begingroup$ @scribbles Prediction are not accurate, and I think it might be because of the warning message which says solution may be non unique. $\endgroup$
    – Jainam
    Commented Aug 12, 2015 at 21:31

1 Answer 1

2
$\begingroup$

Can you define "accurate"? What do you expect to obtain?

It is still a regression and it will not guarantee you 100% precision.

Furthermore quantile regressions will give you the value corresponding to the chosen quantile of the distribution. So, for example, regression with tau=0.25 and some specified value of X will give you y_fit that is greater than 25% of all the observations in the sample for the same X value (25% of observations will lie below y_fit). So in general you shouldn't expect the high accuracy with quantile regressions.

As for the warning, it may be not relevant to your accuracy issue at all. But changing method parameter in qr may help you get rid of the warning. For example, using method="fn" should help in the cases with a high number of observations.

$\endgroup$
3
  • 1
    $\begingroup$ Thank you for your reply. By "accurate" I mean error rate ((actual-predicted)/actual*100) should be minimum 5%. Can I expect this much accuracy from quantile regression? Thanks for answer on warning message. You are correct it was not relevant to accuracy issue. Warning messages were because of same values in data (In my case 0 was repeated for sales on less busy hours) $\endgroup$ Commented Sep 10, 2015 at 19:40
  • 1
    $\begingroup$ The accuracy measure, that you mention, is called in forecasting "Percentage Error" (PE). I assume that you take mean absolute values of PE, which leads to MAPE. The thing with MAPE is that it is scale dependent. So you can obtain 5% when the actuals are high (something like thousands of units) or when the error is very low. In general it is hard to have 5% for some data using any model, so I wouldn't aim for that. And actually you shouldn't aim for some percent. All the different error measures are made for the comparison of models' forecasting accuracy, not the comparison with some value. $\endgroup$ Commented Sep 11, 2015 at 20:54
  • $\begingroup$ Thank you @Ivan Svetunkov , I understood using MAPE is not helpful, hence like you suggested I am going for RMSE ( using Metrics R package). Any other suggestions are welcome. $\endgroup$ Commented Sep 17, 2015 at 22:19

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.