Python PySpark PCA:从模型对象获取组件数

Python PySpark PCA:从模型对象获取组件数,python,apache-spark,pyspark,apache-spark-ml,Python,Apache Spark,Pyspark,Apache Spark Ml,我在PySpark中有一个拟合PCA模型,我需要从模型对象中获取组件的数量 from pyspark.ml.feature import PCA pca = PCA(k=5, inputCol='features', outputCol='components') pca_model = pca.fit(data) 我尝试使用pca_model.k和pca_model.getParam('k'),但它们都没有给出组件的数量 >>> pca_model.k Param(pare

我在PySpark中有一个拟合PCA模型,我需要从模型对象中获取组件的数量

from pyspark.ml.feature import PCA
pca = PCA(k=5, inputCol='features', outputCol='components')
pca_model = pca.fit(data)
我尝试使用
pca_model.k
pca_model.getParam('k')
,但它们都没有给出组件的数量

>>> pca_model.k
Param(parent='PCA_4e66a98132a4fe4ad86c', name='k', doc='the number of principal components (> 0)')
>>> pca_model.getParam('k')
Param(parent='PCA_4e66a98132a4fe4ad86c', name='k', doc='the number of principal components (> 0)')

如何从PySpark的
PCAModel
对象获取组件数量?

您可以使用其Java模型:

pca_model._java_obj.getK()
getOrDefault
方法:

pca_model.getOrDefault("k")