Data Science Asked by Optimizor on July 3, 2021
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[[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
Answered by Zeus on July 3, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP