【问题标题】:Old (sklearn 0.17) GMM, DPGM, VBGMM vs new (sklearn 0.18) GaussianMixture and BayesianGaussianMixture旧的(sklearn 0.17)GMM、DPGM、VBGMM 与新的(sklearn 0.18)GaussianMixture 和 BayesianGaussianMixture
【发布时间】:2016-10-08 11:41:11
【问题描述】:

在之前的 scikit-learn 版本 (0.1.17) 中,我使用以下代码自动确定最佳高斯混合模型并优化无监督聚类的超参数(alpha、协方差类型、bic)。

# Gaussian Mixture Model 
try:       
    # Determine the most suitable covariance_type
    lowest_bic = np.infty
    bic = []
    cv_types = ['spherical', 'tied', 'diag', 'full']
    for cv_type in cv_types:
        # Fit a mixture of Gaussians with EM
        gmm = mixture.GMM(n_components=NUMBER_OF_CLUSTERS, covariance_type=cv_type)
        gmm.fit(transformed_features)
        bic.append(gmm.bic(transformed_features))
        if bic[-1] < lowest_bic:
            lowest_bic = bic[-1]
            best_gmm = gmm
            best_covariance_type = cv_type
    gmm = best_gmm
except Exception, e:       
    print 'Error with GMM estimator. Error: %s' % e 

# Dirichlet Process Gaussian Mixture Model  
try:
    # Determine the most suitable alpha parameter
    alpha = 2/math.log(len(transformed_features))     
    # Determine the most suitable covariance_type
    lowest_bic = np.infty
    bic = []
    cv_types = ['spherical', 'tied', 'diag', 'full']
    for cv_type in cv_types:
        # Fit a mixture of Gaussians with EM
        dpgmm = mixture.DPGMM(n_components=NUMBER_OF_CLUSTERS, covariance_type=cv_type, alpha = alpha)
        dpgmm.fit(transformed_features)
        bic.append(dpgmm.bic(transformed_features))
        if bic[-1] < lowest_bic:
            lowest_bic = bic[-1]
            best_dpgmm = dpgmm
            best_covariance_type = cv_type        
    dpgmm = best_dpgmm                
except Exception, e:       
    print 'Error with DPGMM estimator. Error: %s' % e    

# Variational Inference for Gaussian Mixture Model   
try: 
    # Determine the most suitable alpha parameter 
    alpha = 2/math.log(len(transformed_features))  
    # Determine the most suitable covariance_type
    lowest_bic = np.infty
    bic = []
    cv_types = ['spherical', 'tied', 'diag', 'full']
    for cv_type in cv_types:
        # Fit a mixture of Gaussians with EM
        vbgmm = mixture.VBGMM(n_components=NUMBER_OF_CLUSTERS, covariance_type=cv_type, alpha = alpha)
        vbgmm.fit(transformed_features)
        bic.append(vbgmm.bic(transformed_features))
        if bic[-1] < lowest_bic:
            lowest_bic = bic[-1]
            best_vbgmm = vbgmm
            best_covariance_type = cv_type
    vbgmm = best_vbgmm     
except Exception, e:       
    print 'Error with VBGMM estimator. Error: %s' % e        

如何使用 scikit-learn 0.1.18 中引入的新高斯混合/贝叶斯高斯混合模型实现相同或相似的行为?

根据 scikit-learn 文档,不再有“alpha”参数,而是有“weight_concentration_prior”参数。这些是否相同? http://scikit-learn.org/stable/modules/generated/sklearn.mixture.BayesianGaussianMixture.html#sklearn.mixture.BayesianGaussianMixture

weight_concentration_prior : 浮动 |无,可选。 权重分布上各组分的狄利克雷浓度(狄利克雷)。浓度越高,质量越大 中心并将导致更多组件处于活动状态,而 较低的浓度参数将导致更多的质量在边缘 混合权重单纯形。参数的值必须是 大于0。如果为None,则设置为1。/n_components。

http://scikit-learn.org/0.17/modules/generated/sklearn.mixture.VBGMM.html

alpha: 浮点数,默认 1 : 表示狄利克雷分布的浓度参数的实数。直观地说,alpha 的值越高, 高斯模型的变分混合更有可能使用所有 它可以的组件。

如果这两个参数(alpha 和 weight_concentration_prior)相同,是否意味着公式 alpha = 2/math.log(len(transformed_features)) 仍然适用于 weight_concentration_prior = 2/math.log(len(transformed_features) ))?

【问题讨论】:

    标签: python scikit-learn cluster-analysis gaussian unsupervised-learning


    【解决方案1】:

    BIC 分数仍可用于 GMM 的经典/EM 实现,如 GaussianMixture 类中实现的那样。

    BayesianGaussianMixture 类可以针对给定的alpha 值自动调整有效分量的数量(n_components 应该足够大)。

    您还可以对对数似然使用标准交叉验证(使用模型的score 方法)。

    【讨论】:

    • 好像没有“alpha”参数了。相反,有“weight_concentration_prior”参数。不知道这两个是不是真的一样?
    • 此外,似乎在 GaussianMixture 类中仍然存在 BIC 和 AIC(正如@ogrisel 指出的那样),但在 BayessianGaussianMixture 中没有 BIC 和 AIC。为什么?
    • 新的 weight_concentration_prior 相当于旧的 alpha,除了已弃用的实现有几个错误之外,据我所知,新的实现似乎是正确的。
    • 我认为旧的 VBGMM 具有 bic 方法这一事实不是故意的 VBGMM 是 GMM 的子类,而 BayesianGaussianMixture 不是 GaussianMixture 的直接子类,但它们共享一个共同的基类。我不确定 BIC 分数的实施对于 BayesianGaussianMixture 是否正确。如果是,我们可以将 bic 方法实现移至基类。
    • 参数“weight_concentration_prior”和前面的参数“alpha”一样吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-23
    • 1970-01-01
    • 2022-12-04
    • 2015-02-13
    • 2015-05-19
    • 2021-10-03
    • 2019-04-27
    相关资源
    最近更新 更多