从 GMM 模型绘制高斯子群体

Plot gaussian sub-populations from GMM model

我在 python 上使用 scikit learn 创建了一个 GMM 模型,如下所述:

x = df1['DNA_2']
y = df1['DNA_1']
X = np.column_stack((x, y)) # create a 2D array from the two lists
mod2 = GaussianMixture(n_components=5, covariance_type='tied', random_state=2) # build the gmm
mod2.fit(X)

然后我使用这个模型进行预测,然后绘制:

df1['pred2'] = labels
fig, ax = plt.subplots(1,1)
ax.scatter(x, y, c=df1['pred2'].apply(lambda x: colors[x]), s = 0.5, alpha=0.2)
H,X,Y = density_estimation(x,y)
ax.contour(H, X, Y, 8, linewidths=0.5, cmap='viridis')

获得:

我想知道如何绘制 5 个群体的高斯曲线。我知道我可以使用 mod1.means_ 获得均值,使用 mod1.covariances_ 获得方差(均为 2D),但是如何绘制它以获得每个群体的曲线?

希望得到类似的东西:

如果是像图片这样的2D GMM,唯一的办法就是画一个2D密度图如:https://pythonmachinelearning.pro/clustering-with-gaussian-mixture-models/ 所附的折线图适用于具有三个分量的一维 GMM。要绘制此图,您需要绘制每个 cluster/group.

的概率密度分量