输入数据
的(键,数据点)
A,1,2,0,1,2,1,2,1
B,2,2,3,1,1,1,1,0
C,3,1,2,3,4,5,0,1
d,1,2,0,1,2,5,0,1
....
我有上述格式的输入数据。我想执行Kmeans对上述数据的忽略,忽略第一列,并希望识别每个记录所属的中心。我已经丢弃了第一个col(key)并且能够使用下面的代码找到集群中心,但我期望以下格式输出
(键,cluster_centre)
A,0
B,2
C,1个
d,0
...
代码:
data = sc.textFile("/home/user/inputfile.txt")
parsedData = data.map(lambda line: array([long(x.strip()) for x in line.split(',')]))
model = KMeans.train(parsedData, 3, maxIterations=10, runs=10, initializationMode="random")
centers = model.clusterCenters
for center in centers: print(center)
答案 0 :(得分:0)
filtered_cols = parsed_data.map(lambda x:x [1])
model = KMeans.train(filtered_cols,3,maxIterations = 10,runs = 10,initializationMode =“random”)
centers = model.clusterCenters
中心中心:打印(中心)