Пример #1
0
n_components = range(1,25)
gmms = [GMM(n_components=n, covariance_type='full').fit(xN) for n in n_components]
BICs = [gmm.bic(xN) for gmm in gmms]
i_min = np.argmin(BICs)
clf=gmms[i_min]
print '%s components - BIC %s' %(n_components[i_min],BICs[i_min])
tol = np.percentile(np.exp(clf.score(xN)),10)

# <codecell>

fig1 = plt.figure(figsize=(10, 10))
color_iter = itertools.cycle(['r', 'g', 'b', 'c', 'm','wheat','violet','sienna',
                              'yellow','springgreen','sandybrown','tomato','tan','teal'])

Y_ = clf.predict(xN)
for i, (mean, covar, color) in enumerate(zip(clf.means_, clf._get_covars(), color_iter)):
    v, w = linalg.eigh(covar)
    u = w[0] / linalg.norm(w[0])

    if not np.any(Y_ == i):
        continue
    plt.scatter(xN[Y_ == i, 0], xN[Y_ == i, 1], .8, color=color)

'''X_, Y_ = np.meshgrid(np.linspace(vlim[0], vlim[1]),np.linspace(clim[0], clim[1]))
XX = np.array([X_.ravel(), Y_.ravel()]).T
Z = np.exp(clf.score(XX))
Z = Z.reshape(X_.shape)
CS = plt.contour(X_, Y_, Z)'''

plt.show()