1

我有一个 10000 X 22 维数组(观察 x 特征),我用一个组件拟合高斯混合,如下所示:

mixture = sklearn.mixture.GaussianMixture(n_components=1, covariance_type='full').fit(my_array)

然后,我想根据第 87页中的Bishop 模式识别和机器学习方程 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_mu 和 conditional_cov 时,我得到以下形状:

conditional_mu.shape
(10000, 2)
conditional_cov.shape
(2,2)

我期望 conditional_mu 的形状应该是 (1,2) 因为我只想找到前两个特征的平均值。为什么我会为每个观察结果取一个平均值?

4

1 回答 1

0

是的,这是预期的维度。

对于每个数据点,独立特征是固定的,依赖特征服从正态分布。根据独立特征,每个数据点都会为从属特征提供不同的平均值。

由于您有 10000 个数据点,因此您应该有 10000 个用于相关特征的均值,每个均用于一个数据点。

于 2018-01-20T20:32:05.277 回答