From dcae355c64d7f6fdf61df2feefe464eb96c4cf5e Mon Sep 17 00:00:00 2001 From: Yanbo Liang Date: Mon, 25 Jan 2016 13:54:21 -0800 Subject: [SPARK-12905][ML][PYSPARK] PCAModel return eigenvalues for PySpark ```PCAModel``` can output ```explainedVariance``` at Python side. cc mengxr srowen Author: Yanbo Liang Closes #10830 from yanboliang/spark-12905. --- python/pyspark/ml/feature.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'python') diff --git a/python/pyspark/ml/feature.py b/python/pyspark/ml/feature.py index 141ec3492a..1fa0eab384 100644 --- a/python/pyspark/ml/feature.py +++ b/python/pyspark/ml/feature.py @@ -1987,6 +1987,8 @@ class PCA(JavaEstimator, HasInputCol, HasOutputCol): >>> model = pca.fit(df) >>> model.transform(df).collect()[0].pca_features DenseVector([1.648..., -4.013...]) + >>> model.explainedVariance + DenseVector([0.794..., 0.205...]) .. versionadded:: 1.5.0 """ @@ -2052,6 +2054,15 @@ class PCAModel(JavaModel): """ return self._call_java("pc") + @property + @since("2.0.0") + def explainedVariance(self): + """ + Returns a vector of proportions of variance + explained by each principal component. + """ + return self._call_java("explainedVariance") + @inherit_doc class RFormula(JavaEstimator, HasFeaturesCol, HasLabelCol): -- cgit v1.2.3