BIC为似然函数与参数及样本量的组合,选择该值最小的模型。
np.infty: inf
对GMM模型直接调用bic就可以得到其值
itertools.cycle: 实例化圆形迭代器,zip具有压缩取短的性质。
这里还使用了凸组合:bic.min() * 0.97 + 0.03 * bic.max()
np.infty: inf
对GMM模型直接调用bic就可以得到其值
itertools.cycle: 实例化圆形迭代器,zip具有压缩取短的性质。
这里还使用了凸组合:bic.min() * 0.97 + 0.03 * bic.max()
下面是一个利用BIC选取GMM的例子:
import itertools
import numpy as np
from scipy import linalg
import matplotlib.pyplot as plt
import matplotlib as mpl
from sklearn import mixture
n_samples = 500
np.random.seed(0)
C = np.array([[0, -0.1], [1.7, 0.4]])
X = np.r_[np.dot(np.random.randn(n_samples, 2), C),
0.7 * np.random.randn(n_samples, 2) + np.array([-6, 3])]
lowest_bic = np.infty
bic = []
n_components_range = range(1, 7)
cv_types = ['spherical', 'tied', 'diag', 'full']
for cv_type in cv_types:
for n_components in n_components_range:
gmm = mixture.GMM(n_components = n_components, covariance_type =