gpt4 book ai didi

python - BIC 使用 scikit-learn 中的 GaussianMixture 过度拟合图像分割模型中的组件数量

转载 作者:行者123 更新时间:2023-11-30 09:19:44 25 4
gpt4 key购买 nike

我正在使用 GMM 来分割/聚类 800x800 像素和 4 个波段的高光谱图像数据。

我拍了一张照片并应用 GMM 来聚类像素。
现在,在我目前的情况下,我很容易手动确定图像中有多少个组件。 (草、水、岩石...等)
我已对 n_components=3..8 中的数据手动运行 GMM,并确定 5 个分量可能是对现实进行建模的最佳 n_components。

在未来的应用程序中,我需要能够自动识别我应该在 GMM 中使用的 n_components,因为手动确定是不可能的。

因此,我决定使用 BIC 作为成本函数来确定模型中使用的正确 n_components。
我在测试数据上运行了 BIC,手动确定 n_components=5 是最佳模型现实,发现 BIC 严重过度拟合我的数据。
这建议我使用尽可能多的组件。

newdata=img_data.reshape(800*800,4)
n_components = np.arange(1, 15)
BIC = np.zeros(n_components.shape)

for i, n in enumerate(n_components):
gmm = GaussianMixture(n_components=n,
covariance_type='tied')
gmm.fit(newdata)

BIC[i] = gmm.bic(newdata)
plt.plot(BIC)

BIC Scores as a function of N_components

现在理想情况下,我希望看到我的 BIC 分数最小化为 5,但正如您在上面看到的,它看起来随着 n_components 的增加而不断下降。

有人知道这里会发生什么吗?也许我需要在使用 BIC 之前以某种方式平滑数据以减少噪音?还是我使用BIC功能不当?

最佳答案

因此,经过一番谷歌搜索后,我决定对我的数组应用一个简单的高斯平滑滤波器,它似乎在我的 BIC 分数列表中产生了一个局部最小值,这就是我期望的 n_components 。我编写了一个小脚本来挑选第一个本地最小值并将其用作我的 gmm 模型的参数。

newdata=img_data.reshape(800*800,4)
#Apply a Gaussian smoothing filter over a pixel neighborhood
newdata=sy.ndimage.filters.gaussian_filter(newdata,(1.5,1.5))
#Create the vector of n_components you wish to test using the BIC alogrithm
n_components = np.arange(1, 10)
#Create an empty vector in which to store BIC scores
BIC = np.zeros(n_components.shape)

for i, n in enumerate(n_components):
#Fit gmm to data for each value in n_components vector
gmm = GaussianMixture(n_components=n,
covariance_type='tied')
gmm.fit(newdata)
#Store BIC scores in a list
BIC[i] = gmm.bic(newdata)

#Plot resulting BIC list (Scores(n_components))
plt.plot(BIC)
plt.show()

BIC Scores With Smoothing

关于python - BIC 使用 scikit-learn 中的 GaussianMixture 过度拟合图像分割模型中的组件数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44373504/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com