本文整理汇总了Python中sklearn.mixture.GaussianMixture.score方法的典型用法代码示例。如果您正苦于以下问题:Python GaussianMixture.score方法的具体用法?Python GaussianMixture.score怎么用?Python GaussianMixture.score使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.mixture.GaussianMixture
的用法示例。
在下文中一共展示了GaussianMixture.score方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fit_mixtures
# 需要导入模块: from sklearn.mixture import GaussianMixture [as 别名]
# 或者: from sklearn.mixture.GaussianMixture import score [as 别名]
def fit_mixtures(X,mag,mbins,binwidth=0.2,seed=None,
keepscore=False,keepbic=False,**kwargs):
kwargs.setdefault('n_components',25)
kwargs.setdefault('covariance_type','full')
fits = []
if keepscore:
scores = []
if keepbic:
bics = []
if seed:
np.random.seed(seed)
for bincenter in mbins:
# this is not an efficient way to assign bins, but the time
# is negligible compared to the GMM fitting anyway
ii = np.where( np.abs(mag-bincenter) < binwidth )[0]
if False:
print('{:.2f}: {} qsos'.format(bincenter,len(ii)))
gmm = GaussianMixture(**kwargs)
gmm.fit(X[ii])
fits.append(gmm)
if keepscore:
scores.append(gmm.score(X[ii]))
if keepbic:
bics.append(gmm.bic(X[ii]))
rv = (fits,)
if keepscore:
rv += (scores,)
if keepbic:
rv += (bics,)
return rv
示例2: fit_gmm_to_points
# 需要导入模块: from sklearn.mixture import GaussianMixture [as 别名]
# 或者: from sklearn.mixture.GaussianMixture import score [as 别名]
def fit_gmm_to_points(points,
n_components,
mdl,
ps=[],
num_iter=100,
covariance_type='full',
min_covar=0.001,
init_centers=[],
force_radii=-1.0,
force_weight=-1.0,
mass_multiplier=1.0):
"""fit a GMM to some points. Will return the score and the Akaike score.
Akaike information criterion for the current model fit. It is a measure
of the relative quality of the GMM that takes into account the
parsimony and the goodness of the fit.
if no particles are provided, they will be created
points: list of coordinates (python)
n_components: number of gaussians to create
mdl: IMP Model
ps: list of particles to be decorated. if empty, will add
num_iter: number of EM iterations
covariance_type: covar type for the gaussians. options: 'full', 'diagonal', 'spherical'
min_covar: assign a minimum value to covariance term. That is used to have more spherical
shaped gaussians
init_centers: initial coordinates of the GMM
force_radii: fix the radii (spheres only)
force_weight: fix the weights
mass_multiplier: multiply the weights of all the gaussians by this value
dirichlet: use the DGMM fitting (can reduce number of components, takes longer)
"""
new_sklearn = False
try:
from sklearn.mixture import GMM
except ImportError:
from sklearn.mixture import GaussianMixture
new_sklearn = True
print('creating GMM with n_components',n_components,'n_iter',num_iter,'covar type',covariance_type)
if new_sklearn:
# aic() calls size() on points, so it needs to a numpy array, not a list
points = np.array(points)
weights_init = precisions_init = None
if force_radii != -1.0:
print('warning: radii can no longer be forced, but setting '
'initial values to ', force_radii)
precisions_init = np.array([[1./force_radii]*3
for i in range(n_components)])
if force_weight != -1.0:
print('warning: weights can no longer be forced, but setting '
'initial values to ', force_weight)
weights_init = np.array([force_weight]*n_components)
gmm = GaussianMixture(n_components=n_components,
max_iter=num_iter,
covariance_type=covariance_type,
weights_init=weights_init,
precisions_init=precisions_init,
means_init=None if init_centers==[]
else init_centers)
else:
params='m'
init_params='m'
if force_radii==-1.0:
params+='c'
init_params+='c'
else:
covariance_type='spherical'
print('forcing spherical with radii',force_radii)
if force_weight==-1.0:
params+='w'
init_params+='w'
else:
print('forcing weights to be',force_weight)
gmm = GMM(n_components=n_components, n_iter=num_iter,
covariance_type=covariance_type, min_covar=min_covar,
params=params, init_params=init_params)
if force_weight!=-1.0:
gmm.weights_=np.array([force_weight]*n_components)
if force_radii!=-1.0:
gmm.covars_=np.array([[force_radii]*3 for i in range(n_components)])
if init_centers!=[]:
gmm.means_=init_centers
print('fitting')
model=gmm.fit(points)
score=gmm.score(points)
akaikescore=model.aic(points)
#print('>>> GMM score',gmm.score(points))
### convert format to core::Gaussian
if new_sklearn:
covars = gmm.covariances_
else:
covars = gmm.covars_
for ng in range(n_components):
covar=covars[ng]
#.........这里部分代码省略.........