【发布时间】: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