本文整理汇总了Python中sklearn.cluster.MiniBatchKMeans.dot方法的典型用法代码示例。如果您正苦于以下问题:Python MiniBatchKMeans.dot方法的具体用法?Python MiniBatchKMeans.dot怎么用?Python MiniBatchKMeans.dot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.cluster.MiniBatchKMeans
的用法示例。
在下文中一共展示了MiniBatchKMeans.dot方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initializeWeight
# 需要导入模块: from sklearn.cluster import MiniBatchKMeans [as 别名]
# 或者: from sklearn.cluster.MiniBatchKMeans import dot [as 别名]
def initializeWeight(D, type, N_OUT):
# Here we first whiten the data (PCA or ZCA) and then optionally run k-means
# on this whitened data.
import numpy as np
if D.shape[0] < N_OUT:
print( " Not enough data for '%s' estimation, using elwise"%type )
return np.random.normal(0, 1, (N_OUT,D.shape[1]))
D = D - np.mean(D, axis=0, keepdims=True)
# PCA, ZCA, K-Means
assert type in ['pca', 'zca', 'kmeans', 'rand'], "Unknown initialization type '%s'"%type
C = D.T.dot(D)
s, V = np.linalg.eigh(C)
# order the eigenvalues
ids = np.argsort(s)[-N_OUT:]
s = s[ids]
V = V[:,ids]
s[s<1e-6] = 0
s[s>=1e-6] = 1. / np.sqrt(s[s>=1e-6]+1e-3)
S = np.diag(s)
if type == 'pca':
return S.dot(V.T)
elif type == 'zca':
return V.dot(S.dot(V.T))
# Whiten the data
wD = D.dot(V.dot(S))
wD /= np.linalg.norm(wD, axis=1)[:,None]
if type == 'kmeans':
# Run k-means
from sklearn.cluster import MiniBatchKMeans
km = MiniBatchKMeans(n_clusters = wD.shape[1], batch_size=10*wD.shape[1]).fit(wD).cluster_centers_
elif type == 'rand':
km = wD[np.random.choice(wD.shape[0], wD.shape[1], False)]
C = km.dot(S.dot(V.T))
C /= np.std(D.dot(C.T), axis=0, keepdims=True).T
return C