我有一个10000 X 22维阵列(观测值X特征),我拟合了一个高斯混合,其中一个成分如下:
mixture = sklearn.mixture.GaussianMixture(n_components=1, covariance_type='full').fit(my_array)
然后,我想计算前两个特征相对于其余特征的条件分布的平均值和协方差,根据
Bishop's Pattern Recognition and Machine learning
第87页中的方程式2.81和2.82。我所做的是:
covariances = mixture.covariances_ # shape = (1, 22, 22) where 1 is the 1 component I fit and 22x22 is the covariance matrix
means = mixture_component.means_ # shape = (1, 22), 22 means; one for each feautre
dependent_data = features[:, 0:2] #shape = (10000, 2)
conditional_data = features[:, 2:] #shape = (10000, 20)
mu_a = means[:, 0:2] # Mu of the dependent variables
mu_b = means[:, 2:] # Mu of the independent variables
cov_aa = covariances[0, 0:2, 0:2] # Cov of the dependent vars
cov_bb = covariances[0, 2:, 2:] # Cov of independent vars
cov_ab = covariances[0, 0:2, 2:]
cov_ba = covariances[0, 2:, 0:2]
A = (conditional_data.transpose() - mu_b.transpose())
B = cov_ab.dot(np.linalg.inv(cov_bb))
conditional_mu = mu_a + B.dot(A).transpose()
conditional_cov = cov_aa - cov_ab.dot(np.linalg.inv(cov_bb)).dot(cov_ba)
我的问题是,在计算conditional\u mu和conditional\u cov时,我得到以下形状:
conditional_mu.shape
(10000, 2)
conditional_cov.shape
(2,2)
我希望conditional\u mu的形状应该是(1,2),因为我只想找到前两个特性相对于其余特性的平均值。为什么每次观察我都会得到平均值?