фиктивные данные
from pyspark.ml.linalg import Vectors
from pyspark.ml.clustering import KMeans, KMeansModel
from pyspark.ml.pipeline import Pipeline
data = [(Vectors.dense([0.0, 0.0]),), (Vectors.dense([1.0, 1.0]),),
(Vectors.dense([9.0, 8.0]),), (Vectors.dense([8.0, 9.0]),)]
matrix_normalized = spark.createDataFrame(data, ["scaledFeatures"])
ваш код
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)
просто измените последнюю строку
model.stages[0].clusterCenters()
[array([0.5, 0.5]), array([8., 9.]), array([9., 8.])]