【发布时间】:2016-05-21 02:43:51
【问题描述】:
我正在使用 KMeans 聚类将数据分成 2 个聚类,如下所示。
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn import cluster
##################################################
# load data
clm = np.genfromtxt('data.csv',delimiter=',', skiprows=1)
X = clm[:,(1,12)].astype(float)
# define kmeans learner, then fit with data
kmeans = cluster.KMeans(n_clusters=2)
kmeans.fit(X)
# define centroids
centroids = kmeans.cluster_centers_
labels = kmeans.labels_
#print(centroids)
#print(labels)
#set color
colors = ["g.", "r."]
for i in range(len(X)):
print("coordinate:",X[i], "label:", labels[i])
plt.plot(X[i][0], X[i][1], colors[labels[i]], markersize= 10)
# plot
plt.scatter(centroids[:,0], centroids[:,1], marker = "x", s=150, linewidth = 5, zorder=10)
plt.xlabel('Read proportion')
plt.ylabel('Memory_used_Read')
plt.xlim(0,100)
plt.ylim(ymin=0)
plt.show()
在 KMeans 聚类中,集合 S=(x,y) 没有标记数据,而在 SVM 中,集合 S 输入 x 和目标数据 y。我要做的是在 SVM 中单独使用创建的集群。我不确定如何为每个集群获取 X,y。如果您有任何建议,请告诉我。
谢谢。
【问题讨论】:
标签: python machine-learning svm k-means