本文整理汇总了Python中sklearn.cluster.MiniBatchKMeans.cluster_centers_方法的典型用法代码示例。如果您正苦于以下问题:Python MiniBatchKMeans.cluster_centers_方法的具体用法?Python MiniBatchKMeans.cluster_centers_怎么用?Python MiniBatchKMeans.cluster_centers_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.cluster.MiniBatchKMeans
的用法示例。
在下文中一共展示了MiniBatchKMeans.cluster_centers_方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gen_km
# 需要导入模块: from sklearn.cluster import MiniBatchKMeans [as 别名]
# 或者: from sklearn.cluster.MiniBatchKMeans import cluster_centers_ [as 别名]
def gen_km(meigaras=[], cluster_centers_csv = ""):
strsql = "select count(*) from trade.kabuka "
if len(meigaras) > 0:
strsql = strsql + kf.where_col_in(meigaras, "code")
cnt = sql.exec_selsql(strsql, 0)
km = MiniBatchKMeans(
n_clusters=np.sqrt(cnt*SAMPLE_RATE),
batch_size=1000)
if cluster_centers_csv != "":
path = "%s/%s" % (CSV_DIR, cluster_centers_csv)
if os.path.exists(path):
cluster_centers = f.csv2arr(path)
km.cluster_centers_ = cluster_centers
return km
示例2: _gen_km
# 需要导入模块: from sklearn.cluster import MiniBatchKMeans [as 别名]
# 或者: from sklearn.cluster.MiniBatchKMeans import cluster_centers_ [as 别名]
def _gen_km(self, bolverbose=False):
strsql = "select count(*) from trade.kabuka "
if len(self.meigaras) > 0:
strsql = strsql + " where " + kf.where_col_in(self.meigaras, "code")
cnt = sql.exec_selsql(strsql, 0)[0]
path = "%s/%s" % (CSV_DIR, self.cluster_centers_csv)
X = None
if os.path.exists(path):
X = np.array(f.csv2arr(path))
if X is None:
km = MiniBatchKMeans(n_clusters=int(np.sqrt(cnt * SAMPLE_RATE)), batch_size=1000, verbose=bolverbose)
else:
km = MiniBatchKMeans(
n_clusters=int(np.sqrt(cnt * SAMPLE_RATE)), batch_size=1000, init=X, verbose=bolverbose
)
km.cluster_centers_ = X
self.km = km
示例3: cluster_to_words
# 需要导入模块: from sklearn.cluster import MiniBatchKMeans [as 别名]
# 或者: from sklearn.cluster.MiniBatchKMeans import cluster_centers_ [as 别名]
def cluster_to_words(features, config):
# Create clustering estimator
# KMEANS
# estimator = KMeans(init='k-means++',
# n_clusters=config.SIFT.BoW.num_clusters,
# n_init=10, verbose=True, n_jobs=-2, tol=1e-3)
# Mini batch KMEANS
batch_size = config.SIFT.BoW.num_clusters * 10
estimator = MiniBatchKMeans(init='k-means++',
n_clusters=config.SIFT.BoW.requested_num_clusters,
batch_size=batch_size,
tol=0.001,
init_size=10*config.SIFT.BoW.requested_num_clusters,
n_init = 10,
verbose=True)
# normalize SIFT features
# features = normalize_features(features)
# Cluster features
print "Clustering features into {} clusters".format(estimator.n_clusters)
estimator.fit(features)
# Drop duplicate clusters (usually empty clusters)
clusters = pd.DataFrame(data=estimator.cluster_centers_)
clusters.drop_duplicates(inplace=True)
estimator.cluster_centers_ = np.array(clusters)
estimator.n_clusters = clusters.shape[0]
# Update config to show new number of clusters
configuration.update_config(config,
'SIFT.BoW.num_clusters',
estimator.n_clusters)
# config.SIFT.BoW.num_clusters = estimator.n_clusters
return estimator