绘制概率分布、二维概率分布;
比如,我想生成以下三张图片的散点图,如何做?
1、第一种方案,是数据模型加噪声
比如
(1) y = k*x+b + noise(sigma)
(2) y = -a x^2 + bx + c + noise(sigma)
(3) (x-a)^2+(y-b)^2 = r^2
代码如下;
w = 1.2 b = 0.2 x1 = np.linspace(0, 1, 1000) noise = np.random.randn(1000)*0.2 # noise = np.random.random(1000)*0.2 y1 = w * x1 + b + noise import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.scatter(x1, y1, color = 'r',s=3, label = 'add noise') ax.set_ylim(ymin = 0, ymax = 2.0) plt.show()
a = -8 b = 8 c = 0 x1 = np.linspace(0, 1, 1000) noise = np.random.randn(1000)*0.3 y1 = a*x1**2 + b*x1 + c + noise import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.scatter(x1, y1, color = 'r',s=3, label = 'add noise') # ax.set_ylim(ymin = 0, ymax = 2.0) plt.show()
坑:
为什么噪声成这种样子了? 这是前边已经把seed给固定好了。
应该加这种噪声,正态分布的噪声;