# Sales person performance prediction

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


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[]$$coefficients
ols_model$$month_model[]$$coefficients
ols_model$$qtr_model[]$$coefficients

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

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

mod <- lm(sales~qtr,data=df)
mod\$coefficients

• thanks for the sample code. Would you mind to share some examples in python? May 14 '19 at 9:20
• Would it be possible to integrate/send outputs of ARIMA with a web interface? something like coefficients/weights in ML models. May 14 '19 at 9:35
• 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
– Zeus
May 15 '19 at 3:01
• Sure,will post a new query on the stastical modeling integration with a web. May 15 '19 at 6:43