我用Pypsark创建了一个kmeans算法。现在,我还想提取集群中心。如何将其包含在管道中?这是我到目前为止拥有的代码,但它给我带来了一个错误“AttributeError:'PipelineModel'对象没有属性'clusterCenters'。如何修复?
#### model K-Means ###
from pyspark.ml.clustering import KMeans, KMeansModel
kmeans = KMeans() \
.setK(3) \
.setFeaturesCol("scaledFeatures")\
.setPredictionCol("cluster")
# Chain indexer and tree in a Pipeline
pipeline = Pipeline(stages=[kmeans])
model = pipeline.fit(matrix_normalized)
cluster = model.transform(matrix_normalized)
#get cluster centers
centers = model.clusterCenters()
aluckdog
相关分类