当前位置: 首页>>代码示例>>Python>>正文


Python MeanShift.predict方法代码示例

本文整理汇总了Python中sklearn.cluster.MeanShift.predict方法的典型用法代码示例。如果您正苦于以下问题:Python MeanShift.predict方法的具体用法?Python MeanShift.predict怎么用?Python MeanShift.predict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sklearn.cluster.MeanShift的用法示例。


在下文中一共展示了MeanShift.predict方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: mean_shift

# 需要导入模块: from sklearn.cluster import MeanShift [as 别名]
# 或者: from sklearn.cluster.MeanShift import predict [as 别名]
def mean_shift(model_data, prediction_data = None):
    t0 = time()
    ms = MeanShift().fit(model_data)
    if prediction_data == None:
        labels = ms.predict(model_data)
    else:
        labels = ms.predict(prediction_data)
    means = ms.cluster_centers_
    print "Number of Means:", means.shape[0] 
    print "Mean Shift Time: %0.3f" % (time() - t0)
    return labels, means    
开发者ID:krishnatray,项目名称:CS7641,代码行数:13,代码来源:Clustering.py

示例2: meanshiftt

# 需要导入模块: from sklearn.cluster import MeanShift [as 别名]
# 或者: from sklearn.cluster.MeanShift import predict [as 别名]
def meanshiftt(data):

    bandwidth = estimate_bandwidth(data, quantile=0.2, n_samples=10)
    
    ms = MeanShift(bandwidth=bandwidth, bin_seeding=True)
    
    ms.fit(data)
    idx = ms.predict(data);
    ctrs = ms.cluster_centers_
    return idx, ctrs
开发者ID:beltrame,项目名称:mmMRI,代码行数:12,代码来源:meanshift.py

示例3: clustering_mean_shift

# 需要导入模块: from sklearn.cluster import MeanShift [as 别名]
# 或者: from sklearn.cluster.MeanShift import predict [as 别名]
def clustering_mean_shift(data_res, b):
    """
    Executes the mean shift model from sklearn
    """
    ms = MeanShift(bandwidth=b)
    ms.fit(data_res)

    predictions = ms.predict(data_res)
    cluster_centers = ms.cluster_centers_

    return predictions, cluster_centers
开发者ID:luisc29,项目名称:ide-usage-data,代码行数:13,代码来源:6-mining.py

示例4: pipeline

# 需要导入模块: from sklearn.cluster import MeanShift [as 别名]
# 或者: from sklearn.cluster.MeanShift import predict [as 别名]
def pipeline(chunks, directory, chunks_file_name, chunks_centers_file_name, n_clus, bw):
    """
    Main pipeline for the first phase of data mining.
    Chunks clustering.
    """
    # calculate the proportion of events
    chunks = calc_proportions(chunks)

    print 'Clustering first model...'
    first_model = KMeans(n_clusters=n_clus, n_jobs=8)
    first_model.fit(chunks.ix[:,15:25])
    centers = first_model.cluster_centers_
    
    print 'Clustering second model...'    
    second_model = MeanShift(bandwidth=bw)
    second_model.fit(centers)
    print "Final number of clusters of chunks with MeanShift: " + str(len(second_model.cluster_centers_))
    
    chunks['label'] = second_model.predict(chunks.ix[:,15:25])
    
    centers = DataFrame(second_model.cluster_centers_, columns= TIME_SERIES_NAMES)
    centers.to_csv(directory + chunks_centers_file_name, index=False)

    chunks.to_csv(directory + chunks_file_name, index=False)
开发者ID:luisc29,项目名称:ide-usage-data,代码行数:26,代码来源:5-mining.py

示例5: test_meanshift_predict

# 需要导入模块: from sklearn.cluster import MeanShift [as 别名]
# 或者: from sklearn.cluster.MeanShift import predict [as 别名]
def test_meanshift_predict():
    """Test MeanShift.predict"""
    ms = MeanShift(bandwidth=1.2)
    labels = ms.fit_predict(X)
    labels2 = ms.predict(X)
    assert_array_equal(labels, labels2)
开发者ID:0x0all,项目名称:scikit-learn,代码行数:8,代码来源:test_mean_shift.py

示例6: KMeans

# 需要导入模块: from sklearn.cluster import MeanShift [as 别名]
# 或者: from sklearn.cluster.MeanShift import predict [as 别名]
kmeans2 = KMeans(n_clusters=3, init=km_clcentr[:])
kmeans2.fit(seed_data)
for i in range(datacount):
	kmeans2.labels_[i] += 1

print kmeans2.labels_[:]
# meanshift clustering
bw = estimate_bandwidth(seed_data, quantile=0.2)
#print "MeanShift bandwidth:", bw
ms = MeanShift(bandwidth=bw, bin_seeding=True)
ms.fit(seed_data)
#print ms.labels_[:]

#print seed_res
pred = ms.predict(seed_data)
for i in range(datacount):
	if pred[i] == 0:
		pred[i] = 3

print ms.labels_[:]

print "seedresult-Kmeans accuracy:", accuracy_score(seed_res, kmeans2.labels_)
print "seedresult-Meanshift accuracy:", accuracy_score(seed_res, pred)
print "Kmeans-Meanshift accuracy:", accuracy_score(kmeans2.labels_, pred)

#compdict = []
#for i in range(datacount):
#	compdict.append([seed_res[i], pred[i]])

开发者ID:yminn13,项目名称:ML,代码行数:30,代码来源:cluster_hw.py

示例7:

# 需要导入模块: from sklearn.cluster import MeanShift [as 别名]
# 或者: from sklearn.cluster.MeanShift import predict [as 别名]

for classification in clf.classifications:
	color = colors[classification]
	for featureset in clf.classifications[classification]:
		plt.scatter(featureset[0], featureset[1], marker='x', color=color, s=150, linewidths=5)


unknowns = np.array([[1,3],
					 [8,9],
					 [0,3],
					 [5,4],
					 [6,4]])

for unknown in unknowns:
	classification = clf.predict(unknown)
	plt.scatter(unknown[0], unknown[1], marker='*', color=colors[classification])

plt.show()











开发者ID:xuanzhao,项目名称:master_degree,代码行数:20,代码来源:simple_Kmeans.py


注:本文中的sklearn.cluster.MeanShift.predict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。