【发布时间】:2020-04-03 10:23:27
【问题描述】:
我正在尝试为二进制分类器生成 x 及其标签 - y 的样本。
我知道我的 x 均匀分布在 [0,1] 中。但我的 y 分布由我的 x 派生:
if x in [0.2, 0.4] or in [0.6, 0.8] - P[Y=1] = 0.1。如果 x 超出这些范围,则 P[Y=1] = 0.8 。
我认为最好的方法是使用 NumPy(而不是使用 for 循环和 if 条件),但直到现在我都没有成功。
这是我的尝试:
s = np.random.uniform(0,1,100) # 100 x samples in [0,1] uniformly distributed
condition = (np.logical_or((s>0.2)&(s < 0.4), (s>0.6)&(s < 0.8))) # attempt to mark with True the places of x in bounds.
x_in_bounds = np.select(condlist, s) # this line doesn't work
... # how to generate the y values?
我试图找到一种根据 x 值样本的条件随机生成 y 值的方法,但没有成功。我很想知道我错过了什么。
【问题讨论】:
-
我的回答有帮助吗?不要忘记您可以投票并接受答案。见What should I do when someone answers my question?,谢谢!
标签: python numpy numpy-ndarray