基于条件概率创建数据集

时间:2021-02-26 08:03:13

标签: python numpy

我正在尝试使用以下方法生成数据集:

np.random.standard t
np.random.exponential
np.random.binomial

下面的代码是我目前得到的。

问题是,我不知道如何构建 j... 有什么建议吗?

def data1(n,mu):
    # setting the prob = 0.5 and generating Y =0 or 1
    n1 = np.random.binomial(n,0.5)

    # mu = 2
    n2 = n - n1
    x1 = np.random.standard_t(1, n1) + mu
    # mu = 0
    x2 = np.random.standard_t(1, n2)
    
    # merge x1 and x2 into 1 array
    X = np.concatenate((x1,x2), axis = None)
    X = X.reshape(-1,1)
    
    #Generate the label Y
    Y = np.repeat([0,1],(n1,n2))
    return X,Y


def data2(m,lam):
    # setting the prob = 0.5 and generating Y =0 or 1
    m1 = np.random.binomial(m,0.5) 

    m2 = m-m1
    #lambda = 1,3
    x11 = np.random.exponential(1)
    x22 = np.random.exponential(1/3)
    
    # merge x1 and x2 into 1 array
    Xn = np.concatenate((x11,x22), axis = None)
    Xn = X.reshape(-1,1)
    
    #Generate the label Y
    Yn = np.repeat([0,1],(m1,m2))
    return Xn,Yn

enter image description here

enter image description here

0 个答案:

没有答案