1
$\begingroup$

I am trying to predict/forecast salesperson performance weekly, monthly, quarterly, and yearly based on the products that they sold over 3 years. As part of this effort, I grouped their number of units sold by the state, location, stores, product types, and sale dates.

By using this information I grouped their id and month of sales and number of units sold. Example data is shown below.

For ARIMA modeling, does this format work well enough to predict/forecast salesperson performance weekly, monthly, quartely, and yearly?

Id      Month   Units
65381   201703  467.0
65381   201710  3.0
65381   201712  6.0
65381   201803  20.0
65381   201805  2.0
65381   201807  20.0
65381   201812  16.0
65381   201904  2.0
$\endgroup$

1 Answer 1

0
$\begingroup$

Here is a simple way of fitting a linear model to each salesperson by week, month and quarter. You'll need to extract the week, month and quarter from the date using the lubridate package.

library(lubridate)
library(tidyverse)

#create fake data
n_var <- 50
id <- sample(x=seq(from=1,to=4),size=n_var,replace=TRUE)
dte <- sample(seq(as.Date('2018/01/01'), as.Date('2019/01/01'), by="day"), size=n_var)
sales <- runif(min=0,max=25,n=n_var)

sales_data <- data.frame(id,dte,sales) %>% 
  mutate(
    weeknumber=week(dte),
    month=month(dte),
    qtr=quarter(dte)

  )

#fit an OLS model
ols_model <- sales_data %>% 
  group_by(id) %>% 
  summarise(
    week_model=list(lm(sales~weeknumber)),
    month_model=list(lm(sales~month)),
    qtr_model=list(lm(sales~qtr))
    )

#extract coefficients
ols_model$week_model[[1]]$coefficients
ols_model$month_model[[1]]$coefficients
ols_model$qtr_model[[1]]$coefficients

ols_model$week_model[[2]]$coefficients
ols_model$month_model[[2]]$coefficients
ols_model$qtr_model[[3]]$coefficients

#simple version on one id
df <- sales_data %>% 
  filter(id==1)

mod <- lm(sales~qtr,data=df)
mod$coefficients
$\endgroup$
4
  • $\begingroup$ thanks for the sample code. Would you mind to share some examples in python? $\endgroup$
    – Optimizor
    May 14, 2019 at 9:20
  • $\begingroup$ Would it be possible to integrate/send outputs of ARIMA with a web interface? something like coefficients/weights in ML models. $\endgroup$
    – Optimizor
    May 14, 2019 at 9:35
  • $\begingroup$ Sorry I don't python well enough to convert the code, but take a look at this site xavierdupre.fr/app/pyensae/helpsphinx/notebooks/r2python.html . I'm sure you could integrate with a web page, best to ask another question $\endgroup$
    – Zeus
    May 15, 2019 at 3:01
  • $\begingroup$ Sure,will post a new query on the stastical modeling integration with a web. $\endgroup$
    – Optimizor
    May 15, 2019 at 6:43

Your Answer

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

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