我使用scikit在python上学习了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_
来获得方差(都是二维的),但是我该如何绘制它以获得每个总体的曲线?
答案 0 :(得分:0)
如果是图片的2D GMM,则唯一的方法是绘制2D密度图,例如:https://pythonmachinelearning.pro/clustering-with-gaussian-mixture-models/ 附加的线图适用于具有三个组件的一维GMM。要绘制此图,需要绘制每个聚类/组的概率密度分量。