Modelling promotions for demand forecasting












0












$begingroup$


I am trying to develop a model to predict future demand for a product. Now, there are always some promotional events that affect the sales. I am trying to solve this problem using dummy variables. Here's how:



Supposing that the firm runs 7 promotional events on a particular product. So, I construct 7 dummy variables, that are boolean. For supposing that a for a particular week, promotion 3 was running. So, my training data-point becomes [0,0,1,0,0,0,0] and the corresponding sales. I construct a linear regression model for promotions in this way.



Now, here is my problem. When we model seasonality using this method, we construct a base linear model, after deseasonalising the data, and then use the two models to predict the final output. In case of promotions, how do I 'depromotionalise' the data?



Any tips in solving the problem are appreciated. Thanks!










share|improve this question









$endgroup$




bumped to the homepage by Community yesterday


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.




















    0












    $begingroup$


    I am trying to develop a model to predict future demand for a product. Now, there are always some promotional events that affect the sales. I am trying to solve this problem using dummy variables. Here's how:



    Supposing that the firm runs 7 promotional events on a particular product. So, I construct 7 dummy variables, that are boolean. For supposing that a for a particular week, promotion 3 was running. So, my training data-point becomes [0,0,1,0,0,0,0] and the corresponding sales. I construct a linear regression model for promotions in this way.



    Now, here is my problem. When we model seasonality using this method, we construct a base linear model, after deseasonalising the data, and then use the two models to predict the final output. In case of promotions, how do I 'depromotionalise' the data?



    Any tips in solving the problem are appreciated. Thanks!










    share|improve this question









    $endgroup$




    bumped to the homepage by Community yesterday


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      0












      0








      0





      $begingroup$


      I am trying to develop a model to predict future demand for a product. Now, there are always some promotional events that affect the sales. I am trying to solve this problem using dummy variables. Here's how:



      Supposing that the firm runs 7 promotional events on a particular product. So, I construct 7 dummy variables, that are boolean. For supposing that a for a particular week, promotion 3 was running. So, my training data-point becomes [0,0,1,0,0,0,0] and the corresponding sales. I construct a linear regression model for promotions in this way.



      Now, here is my problem. When we model seasonality using this method, we construct a base linear model, after deseasonalising the data, and then use the two models to predict the final output. In case of promotions, how do I 'depromotionalise' the data?



      Any tips in solving the problem are appreciated. Thanks!










      share|improve this question









      $endgroup$




      I am trying to develop a model to predict future demand for a product. Now, there are always some promotional events that affect the sales. I am trying to solve this problem using dummy variables. Here's how:



      Supposing that the firm runs 7 promotional events on a particular product. So, I construct 7 dummy variables, that are boolean. For supposing that a for a particular week, promotion 3 was running. So, my training data-point becomes [0,0,1,0,0,0,0] and the corresponding sales. I construct a linear regression model for promotions in this way.



      Now, here is my problem. When we model seasonality using this method, we construct a base linear model, after deseasonalising the data, and then use the two models to predict the final output. In case of promotions, how do I 'depromotionalise' the data?



      Any tips in solving the problem are appreciated. Thanks!







      machine-learning time-series regression forecast






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 8 '18 at 6:49









      Prashant PandeyPrashant Pandey

      1212




      1212





      bumped to the homepage by Community yesterday


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community yesterday


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          1 Answer
          1






          active

          oldest

          votes


















          0












          $begingroup$

          To create dummy variables for days promotion holidays, you might find this example useful.



          If you are sure you do not have an out-of-stock problem anytime in the history you could use an autoregressive model to predict future sales (demand) for any product that has historical data. Depending on your data you could choose a model. Following code is an example which combines four different models by giving different weight to different models. This type of models capture seasonality and trends of your data. For more details about the models please check Rob Hyndman's forecast package documentation.



          choose_model<-function(x,h,reg,new_reg,end_train,start_test){
          library(forecast)
          library(tidyverse)


          #train data

          x_train <- window(x, end = end_train )

          x_test <- window(x, start = start_test)

          #train and test for regressors

          reg_train <- window(reg, end = end_train )

          reg_test <- window(reg, start = start_test)

          h1=length(x_test)

          #model1

          stlf(x_train , method="arima",s.window= nrow(x_train),xreg = reg_train, newxreg = reg_test, h=h1)-> fc_stlf_xreg

          #model2
          auto.arima(x_train, stepwise = FALSE, approximation = FALSE,xreg=reg_train)%>%forecast(h=h1,xreg=reg_test) -> fc_arima_xreg

          #model3
          set.seed(12345)#for nnetar model
          nnetar(x_train, MaxNWts=nrow(x), xreg=reg_train)%>%forecast(h=h1, xreg=reg_test) -> fc_nnetar_xreg

          #model4
          stlf(x_train , method= "ets",s.window= 12, h=h1)-> fc_stlf_ets

          #Combination

          mod1 <- lm(x_test ~ 0 + fc_stlf_xreg$mean + fc_arima_xreg$mean + fc_nnetar_xreg$mean + fc_stlf_ets$mean)
          mod2 <- lm(x_test/I(sum(coef(mod1))) ~ 0 + fc_stlf_xreg$mean + fc_arima_xreg$mean + fc_nnetar_xreg$mean + fc_stlf_ets$mean)



          #model1

          stlf(x, method="arima",s.window= 12,xreg=reg, newxreg=new_reg, h=h)-> fc_stlf

          #model2
          auto.arima(x, stepwise = FALSE, approximation = FALSE,xreg=reg)%>%forecast(h=h,xreg=new_reg) -> fc_arima

          #model3
          set.seed(12345)#for nnetar model
          nnetar(x, MaxNWts=nrow(x), xreg=reg)%>%forecast(h=h, xreg=new_reg) -> fc_nnetar

          #model4
          stlf(x , method= "ets",s.window= 12, h=h)-> fc_stlf_e

          #Combination

          Combi <- (mod2$coefficients[[1]]*fc_stlf$mean + mod2$coefficients[[2]]*fc_arima$mean +
          mod2$coefficients[[3]]*fc_nnetar$mean + mod2$coefficients[[4]]*fc_stlf_e$mean)

          return(Combi)
          }


          The usage of the function:



          coose_model(x,h,reg,new_reg,c(2018,02),c(2018,3))


          $x$ is a time series



          $h$ is time horizon to predict



          $reg$ is the historical promotions, dummy date variables, holidays...



          $new_ reg$ is the promotions, dummy date variables, holidays that are that you know it is going to happen



          If you know that there is out-of-stock problem then take a look to this paper.






          share|improve this answer











          $endgroup$














            Your Answer





            StackExchange.ifUsing("editor", function () {
            return StackExchange.using("mathjaxEditing", function () {
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
            });
            });
            }, "mathjax-editing");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "557"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f36623%2fmodelling-promotions-for-demand-forecasting%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0












            $begingroup$

            To create dummy variables for days promotion holidays, you might find this example useful.



            If you are sure you do not have an out-of-stock problem anytime in the history you could use an autoregressive model to predict future sales (demand) for any product that has historical data. Depending on your data you could choose a model. Following code is an example which combines four different models by giving different weight to different models. This type of models capture seasonality and trends of your data. For more details about the models please check Rob Hyndman's forecast package documentation.



            choose_model<-function(x,h,reg,new_reg,end_train,start_test){
            library(forecast)
            library(tidyverse)


            #train data

            x_train <- window(x, end = end_train )

            x_test <- window(x, start = start_test)

            #train and test for regressors

            reg_train <- window(reg, end = end_train )

            reg_test <- window(reg, start = start_test)

            h1=length(x_test)

            #model1

            stlf(x_train , method="arima",s.window= nrow(x_train),xreg = reg_train, newxreg = reg_test, h=h1)-> fc_stlf_xreg

            #model2
            auto.arima(x_train, stepwise = FALSE, approximation = FALSE,xreg=reg_train)%>%forecast(h=h1,xreg=reg_test) -> fc_arima_xreg

            #model3
            set.seed(12345)#for nnetar model
            nnetar(x_train, MaxNWts=nrow(x), xreg=reg_train)%>%forecast(h=h1, xreg=reg_test) -> fc_nnetar_xreg

            #model4
            stlf(x_train , method= "ets",s.window= 12, h=h1)-> fc_stlf_ets

            #Combination

            mod1 <- lm(x_test ~ 0 + fc_stlf_xreg$mean + fc_arima_xreg$mean + fc_nnetar_xreg$mean + fc_stlf_ets$mean)
            mod2 <- lm(x_test/I(sum(coef(mod1))) ~ 0 + fc_stlf_xreg$mean + fc_arima_xreg$mean + fc_nnetar_xreg$mean + fc_stlf_ets$mean)



            #model1

            stlf(x, method="arima",s.window= 12,xreg=reg, newxreg=new_reg, h=h)-> fc_stlf

            #model2
            auto.arima(x, stepwise = FALSE, approximation = FALSE,xreg=reg)%>%forecast(h=h,xreg=new_reg) -> fc_arima

            #model3
            set.seed(12345)#for nnetar model
            nnetar(x, MaxNWts=nrow(x), xreg=reg)%>%forecast(h=h, xreg=new_reg) -> fc_nnetar

            #model4
            stlf(x , method= "ets",s.window= 12, h=h)-> fc_stlf_e

            #Combination

            Combi <- (mod2$coefficients[[1]]*fc_stlf$mean + mod2$coefficients[[2]]*fc_arima$mean +
            mod2$coefficients[[3]]*fc_nnetar$mean + mod2$coefficients[[4]]*fc_stlf_e$mean)

            return(Combi)
            }


            The usage of the function:



            coose_model(x,h,reg,new_reg,c(2018,02),c(2018,3))


            $x$ is a time series



            $h$ is time horizon to predict



            $reg$ is the historical promotions, dummy date variables, holidays...



            $new_ reg$ is the promotions, dummy date variables, holidays that are that you know it is going to happen



            If you know that there is out-of-stock problem then take a look to this paper.






            share|improve this answer











            $endgroup$


















              0












              $begingroup$

              To create dummy variables for days promotion holidays, you might find this example useful.



              If you are sure you do not have an out-of-stock problem anytime in the history you could use an autoregressive model to predict future sales (demand) for any product that has historical data. Depending on your data you could choose a model. Following code is an example which combines four different models by giving different weight to different models. This type of models capture seasonality and trends of your data. For more details about the models please check Rob Hyndman's forecast package documentation.



              choose_model<-function(x,h,reg,new_reg,end_train,start_test){
              library(forecast)
              library(tidyverse)


              #train data

              x_train <- window(x, end = end_train )

              x_test <- window(x, start = start_test)

              #train and test for regressors

              reg_train <- window(reg, end = end_train )

              reg_test <- window(reg, start = start_test)

              h1=length(x_test)

              #model1

              stlf(x_train , method="arima",s.window= nrow(x_train),xreg = reg_train, newxreg = reg_test, h=h1)-> fc_stlf_xreg

              #model2
              auto.arima(x_train, stepwise = FALSE, approximation = FALSE,xreg=reg_train)%>%forecast(h=h1,xreg=reg_test) -> fc_arima_xreg

              #model3
              set.seed(12345)#for nnetar model
              nnetar(x_train, MaxNWts=nrow(x), xreg=reg_train)%>%forecast(h=h1, xreg=reg_test) -> fc_nnetar_xreg

              #model4
              stlf(x_train , method= "ets",s.window= 12, h=h1)-> fc_stlf_ets

              #Combination

              mod1 <- lm(x_test ~ 0 + fc_stlf_xreg$mean + fc_arima_xreg$mean + fc_nnetar_xreg$mean + fc_stlf_ets$mean)
              mod2 <- lm(x_test/I(sum(coef(mod1))) ~ 0 + fc_stlf_xreg$mean + fc_arima_xreg$mean + fc_nnetar_xreg$mean + fc_stlf_ets$mean)



              #model1

              stlf(x, method="arima",s.window= 12,xreg=reg, newxreg=new_reg, h=h)-> fc_stlf

              #model2
              auto.arima(x, stepwise = FALSE, approximation = FALSE,xreg=reg)%>%forecast(h=h,xreg=new_reg) -> fc_arima

              #model3
              set.seed(12345)#for nnetar model
              nnetar(x, MaxNWts=nrow(x), xreg=reg)%>%forecast(h=h, xreg=new_reg) -> fc_nnetar

              #model4
              stlf(x , method= "ets",s.window= 12, h=h)-> fc_stlf_e

              #Combination

              Combi <- (mod2$coefficients[[1]]*fc_stlf$mean + mod2$coefficients[[2]]*fc_arima$mean +
              mod2$coefficients[[3]]*fc_nnetar$mean + mod2$coefficients[[4]]*fc_stlf_e$mean)

              return(Combi)
              }


              The usage of the function:



              coose_model(x,h,reg,new_reg,c(2018,02),c(2018,3))


              $x$ is a time series



              $h$ is time horizon to predict



              $reg$ is the historical promotions, dummy date variables, holidays...



              $new_ reg$ is the promotions, dummy date variables, holidays that are that you know it is going to happen



              If you know that there is out-of-stock problem then take a look to this paper.






              share|improve this answer











              $endgroup$
















                0












                0








                0





                $begingroup$

                To create dummy variables for days promotion holidays, you might find this example useful.



                If you are sure you do not have an out-of-stock problem anytime in the history you could use an autoregressive model to predict future sales (demand) for any product that has historical data. Depending on your data you could choose a model. Following code is an example which combines four different models by giving different weight to different models. This type of models capture seasonality and trends of your data. For more details about the models please check Rob Hyndman's forecast package documentation.



                choose_model<-function(x,h,reg,new_reg,end_train,start_test){
                library(forecast)
                library(tidyverse)


                #train data

                x_train <- window(x, end = end_train )

                x_test <- window(x, start = start_test)

                #train and test for regressors

                reg_train <- window(reg, end = end_train )

                reg_test <- window(reg, start = start_test)

                h1=length(x_test)

                #model1

                stlf(x_train , method="arima",s.window= nrow(x_train),xreg = reg_train, newxreg = reg_test, h=h1)-> fc_stlf_xreg

                #model2
                auto.arima(x_train, stepwise = FALSE, approximation = FALSE,xreg=reg_train)%>%forecast(h=h1,xreg=reg_test) -> fc_arima_xreg

                #model3
                set.seed(12345)#for nnetar model
                nnetar(x_train, MaxNWts=nrow(x), xreg=reg_train)%>%forecast(h=h1, xreg=reg_test) -> fc_nnetar_xreg

                #model4
                stlf(x_train , method= "ets",s.window= 12, h=h1)-> fc_stlf_ets

                #Combination

                mod1 <- lm(x_test ~ 0 + fc_stlf_xreg$mean + fc_arima_xreg$mean + fc_nnetar_xreg$mean + fc_stlf_ets$mean)
                mod2 <- lm(x_test/I(sum(coef(mod1))) ~ 0 + fc_stlf_xreg$mean + fc_arima_xreg$mean + fc_nnetar_xreg$mean + fc_stlf_ets$mean)



                #model1

                stlf(x, method="arima",s.window= 12,xreg=reg, newxreg=new_reg, h=h)-> fc_stlf

                #model2
                auto.arima(x, stepwise = FALSE, approximation = FALSE,xreg=reg)%>%forecast(h=h,xreg=new_reg) -> fc_arima

                #model3
                set.seed(12345)#for nnetar model
                nnetar(x, MaxNWts=nrow(x), xreg=reg)%>%forecast(h=h, xreg=new_reg) -> fc_nnetar

                #model4
                stlf(x , method= "ets",s.window= 12, h=h)-> fc_stlf_e

                #Combination

                Combi <- (mod2$coefficients[[1]]*fc_stlf$mean + mod2$coefficients[[2]]*fc_arima$mean +
                mod2$coefficients[[3]]*fc_nnetar$mean + mod2$coefficients[[4]]*fc_stlf_e$mean)

                return(Combi)
                }


                The usage of the function:



                coose_model(x,h,reg,new_reg,c(2018,02),c(2018,3))


                $x$ is a time series



                $h$ is time horizon to predict



                $reg$ is the historical promotions, dummy date variables, holidays...



                $new_ reg$ is the promotions, dummy date variables, holidays that are that you know it is going to happen



                If you know that there is out-of-stock problem then take a look to this paper.






                share|improve this answer











                $endgroup$



                To create dummy variables for days promotion holidays, you might find this example useful.



                If you are sure you do not have an out-of-stock problem anytime in the history you could use an autoregressive model to predict future sales (demand) for any product that has historical data. Depending on your data you could choose a model. Following code is an example which combines four different models by giving different weight to different models. This type of models capture seasonality and trends of your data. For more details about the models please check Rob Hyndman's forecast package documentation.



                choose_model<-function(x,h,reg,new_reg,end_train,start_test){
                library(forecast)
                library(tidyverse)


                #train data

                x_train <- window(x, end = end_train )

                x_test <- window(x, start = start_test)

                #train and test for regressors

                reg_train <- window(reg, end = end_train )

                reg_test <- window(reg, start = start_test)

                h1=length(x_test)

                #model1

                stlf(x_train , method="arima",s.window= nrow(x_train),xreg = reg_train, newxreg = reg_test, h=h1)-> fc_stlf_xreg

                #model2
                auto.arima(x_train, stepwise = FALSE, approximation = FALSE,xreg=reg_train)%>%forecast(h=h1,xreg=reg_test) -> fc_arima_xreg

                #model3
                set.seed(12345)#for nnetar model
                nnetar(x_train, MaxNWts=nrow(x), xreg=reg_train)%>%forecast(h=h1, xreg=reg_test) -> fc_nnetar_xreg

                #model4
                stlf(x_train , method= "ets",s.window= 12, h=h1)-> fc_stlf_ets

                #Combination

                mod1 <- lm(x_test ~ 0 + fc_stlf_xreg$mean + fc_arima_xreg$mean + fc_nnetar_xreg$mean + fc_stlf_ets$mean)
                mod2 <- lm(x_test/I(sum(coef(mod1))) ~ 0 + fc_stlf_xreg$mean + fc_arima_xreg$mean + fc_nnetar_xreg$mean + fc_stlf_ets$mean)



                #model1

                stlf(x, method="arima",s.window= 12,xreg=reg, newxreg=new_reg, h=h)-> fc_stlf

                #model2
                auto.arima(x, stepwise = FALSE, approximation = FALSE,xreg=reg)%>%forecast(h=h,xreg=new_reg) -> fc_arima

                #model3
                set.seed(12345)#for nnetar model
                nnetar(x, MaxNWts=nrow(x), xreg=reg)%>%forecast(h=h, xreg=new_reg) -> fc_nnetar

                #model4
                stlf(x , method= "ets",s.window= 12, h=h)-> fc_stlf_e

                #Combination

                Combi <- (mod2$coefficients[[1]]*fc_stlf$mean + mod2$coefficients[[2]]*fc_arima$mean +
                mod2$coefficients[[3]]*fc_nnetar$mean + mod2$coefficients[[4]]*fc_stlf_e$mean)

                return(Combi)
                }


                The usage of the function:



                coose_model(x,h,reg,new_reg,c(2018,02),c(2018,3))


                $x$ is a time series



                $h$ is time horizon to predict



                $reg$ is the historical promotions, dummy date variables, holidays...



                $new_ reg$ is the promotions, dummy date variables, holidays that are that you know it is going to happen



                If you know that there is out-of-stock problem then take a look to this paper.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Aug 13 '18 at 7:43

























                answered Aug 12 '18 at 22:28









                AkaiAkai

                664




                664






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Data Science Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    Use MathJax to format equations. MathJax reference.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f36623%2fmodelling-promotions-for-demand-forecasting%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to label and detect the document text images

                    Vallis Paradisi

                    Tabula Rosettana