【发布时间】:2017-11-19 09:58:25
【问题描述】:
假设我们有一个服务,其中 # 个请求即将到来,我们每小时添加这些请求,例如来自 12-1 和 1-2 等。所以我想做的是生成这些请求数量跟随泊松到达,然后将其添加到表示一周中某一天的字典中
monday = [hour_range, number_of_clients_in_that_hour]
最后,我们将拥有这 7 个以 Mon to Sunday 命名的字典,在这些字典上可以使用一些线性回归来预测给定一天中下一小时的客户数。
所以基本上,当我在 python 中模拟这个场景时,我需要进行一个代表这种场景的到达。我有以下代码,使用它使用均匀分布生成# of clients in an hour。对于泊松到达或任何其他真正代表这种情况的到达,我该怎么做?我的代码如下
day_names = ['mon','tue','wed','thurs','fri','sat','sun']
time_values = np.linspace(1,23,23,dtype='int') # print from 1,2...23
for day_iterator in range(1,7+1):
number_of_clients = [] # create empty list that will hold number of clients
for i in range(1,24,1): # lets create no. of clients for a day on an hourly basis in this for loop
rand_value = random.randint(1,20) # generate number of clients
number_of_clients.append(rand_value) # append the number of clients to this list
# a single day data is generated after this for
locals() [day_names[day_iterator-1]] = dict(zip(time_values,number_of_clients)) # create dict for each day of a week
# print each day
print "monday = %s"%mon
print "tuesday = %s"%tue
print "wed = %s"%wed
print "thurs = %s"%thurs
print "fri = %s"%fri
print "sat = %s"%sat
print "sun = %s"%sun
plt.plot(mon.keys(),mon.values())
【问题讨论】:
标签: python statistics poisson