【发布时间】:2021-09-05 17:07:14
【问题描述】:
我想生成一个二维样本数据集。我复制了link 中所述的代码并将其翻倍以生成向量 X、Y 以将它们分散为二维数据集,如下所示。但结果并不理想。事实上,我想要下图这样的东西。
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
mu = [1,4]
sigma = [2, 1]
p_i = [0.3, 0.7]
n = 1000
x = []
y=[]
for i in range(n):
z_i = np.argmax(np.random.multinomial(1, p_i)) #np.random.multinomial(1,[0.3,0.5,0.2]) returns the result of an experiment
#of rolling a dice. the result is as this: [1,0,0]. this means that the side one occurs in the experiment and the others
#not. the goal is choosing mu[i] in a random way
x_i = np.random.normal(mu[z_i], sigma[z_i])
x.append(x_i)
mu = [3,6]
sigma = [1, 2]
p_i = [0.6, 0.4]
for i in range(n):
z_i = np.argmax(np.random.multinomial(1, p_i)) #np.random.multinomial(1,[0.3,0.5,0.2]) returns the result of an experiment
#of rolling a dice. the result is as this: [1,0,0]. this means that the side one occurs in the experiment and the others
#not. the goal is choosing mu[i] in a random way
y_i = np.random.normal(mu[z_i], sigma[z_i])
y.append(y_i)
plt.scatter(x, y)
plt.show()
谁能帮帮我?
【问题讨论】:
标签: python numpy matplotlib dataset