在学习生活中,我们经常性的发现有很多事物背后都有某种规律,而且,这种规律可能符合某种随机分布,比如:正态分布、对数正态分布、beta分布等等。
所以,了解某种分布对一些事物有更加深入的理解并能清楚的阐释事物的规律性。现在,用python产生一组随机数据,来演示这些分布:
import random
import matplotlib
import matplotlib.pyplot as plt
SAMPLE_SIZE = 1000
buckets = 100
fig = plt.figure()
matplotlib.rcParams.update({"font.size": 7})
#第一个图形是在[0,1)之间分布的随机变量(normal distributed random variable)。
ax = fig.add_subplot(5,2,1)
ax.set_xlabel("random.random")
res = [random.random() for _ in xrange(1, SAMPLE_SIZE)]
ax.hist(res, buckets)
#第二个图形是一个均匀分布的随机变量(uniformly distributed random variable)。
ax_2 = fig.add_subplot(5,2,2)
ax_2.set_xlabel("random.uniform")
a = 1
b = SAMPLE_SIZE
res_2 = [random.uniform(a, b) fo