【问题标题】:BIC is over-fitting the number of components in an image segmentation model using GaussianMixture from scikit-learnBIC 使用来自 scikit-learn 的 GaussianMixture 过度拟合图像分割模型中的组件数量
【发布时间】:2017-11-06 11:54:38
【问题描述】:

我正在使用 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 分数最小化为 5,但正如您在上面看到的那样,它看起来随着 n_components 不断下降。

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

【问题讨论】:

    标签: python image-processing machine-learning scikit-learn cluster-analysis


    【解决方案1】:

    所以经过一番谷歌搜索后,我决定对我的数组应用一个简单的高斯平滑滤波器,它似乎在我的 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

    【讨论】:

      猜你喜欢
      • 2014-01-07
      • 2016-11-26
      • 2018-02-09
      • 2021-05-09
      • 2015-03-25
      • 2018-04-09
      • 2015-12-01
      • 2017-07-13
      • 2019-08-18
      相关资源
      最近更新 更多