条件分布的均值和协方差

Mean and covariance of conditional distribution

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

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

然后,我想根据第 87 页中的 Bishop's Pattern Recognition and Machine learning 方程 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),因为我只想找到前两个特征的均值。为什么我得到的是每次观察的平均值?

是的,这是预期的尺寸。

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

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