Practical Predictive Analytics
上QQ阅读APP看书,第一时间看更新

Example – simulating customer service calls

In this example, we can simulate calls to the customer service which might occur at the beginning and at the end of the week. Management projects that weekend volume will be heavy, with an average of 1500000 calls and an average turnaround time of 4 minutes. Customer service call volume for Monday-Thursday is estimated as handling 1000000 calls with an average turnaround time of 1 minute. We could use this simulation to build a model to include weekends versus nonweekends as new variables in a predictive model:

library(ggplot2) 
library(grid)
library(gridExtra)
set.seed(123)
MonTuesWedThurs=rnorm(1000000,1,1)
FriSatSun=rnorm(1500000,4,1)
weekly = c(MonTuesWedThurs,FriSatSun)

If we were interested in looking at the difference in call volumes, we could look at them individually (as shown in the top row of the following plot) or as a combined distribution for weekends and nonweekends. The combined plot is one way of illustrating the difference between weekends and nonweekends, and shows that they have similar shapes, but different mean values:

p1 = ggplot(data.frame(FriSatSun), aes(x=FriSatSun)) + stat_bin(binwidth=0.25, position="identity") 

p2 = ggplot(data.frame(MonTuesWedThurs), aes(x=MonTuesWedThurs)) + stat_bin(binwidth=0.25, position="identity")

p3 = ggplot(data.frame(weekly), aes(x=weekly)) + stat_bin(binwidth=0.25, position="identity")

grid.arrange(p1, p2, p3, ncol = 2)