def free_parameters(self, data):
"""
Compute free parameters for the model fit using K-Means
"""
K = np.unique(self.labels_).shape[0] # number of clusters
n, d = data.shape
r = (K - 1) + (K * d)
if self.metric == 'euclidean':
r += 1 # one parameter for variance
elif self.metric == 'mahalanobis':
if self.covar_type == 'full' and self.covar_tied:
r += (d * (d + 1) * 0.5) # half of the elements (including diagonal) in the matrix
if self.covar_type == 'full' and not self.covar_tied:
r += (d * (d + 1) * 0.5 * K) # half of the elements (including diagonal) in the matrix
if self.covar_type == 'diag' and self.covar_tied:
r += d # diagonal elements of the matrix
if self.covar_type == 'diag' and not self.covar_tied:
r += (d * K) # diagonal elements of the matrix
if self.covar_type == 'spher' and self.covar_tied:
r += 1 # all diagonal elements are equal
if self.covar_type == 'spher' and not self.covar_tied:
r += K # all diagonal elements are equal
return r
评论列表
文章目录