【问题标题】:PySpark PCA: get number of components from model objectPySpark PCA:从模型对象中获取组件数量
【发布时间】:2018-05-22 17:12:34
【问题描述】:

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

from pyspark.ml.feature import PCA
pca = PCA(k=5, inputCol='features', outputCol='components')
pca_model = pca.fit(data)

我尝试使用pca_model.kpca_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 对象中获取组件的数量?

【问题讨论】:

    标签: python apache-spark pyspark apache-spark-ml


    【解决方案1】:

    你可以使用它的Java模型:

    pca_model._java_obj.getK()
    

    getOrDefault方法:

    pca_model.getOrDefault("k")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-30
      • 1970-01-01
      • 2013-07-25
      • 1970-01-01
      • 2012-12-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多