Skip to content
Snippets Groups Projects
Commit dcae355c authored by Yanbo Liang's avatar Yanbo Liang Committed by Xiangrui Meng
Browse files

[SPARK-12905][ML][PYSPARK] PCAModel return eigenvalues for PySpark

```PCAModel```  can output ```explainedVariance``` at Python side.

cc mengxr srowen

Author: Yanbo Liang <ybliang8@gmail.com>

Closes #10830 from yanboliang/spark-12905.
parent 9348431d
No related branches found
No related tags found
No related merge requests found
......@@ -102,6 +102,8 @@ object PCA extends DefaultParamsReadable[PCA] {
* Model fitted by [[PCA]].
*
* @param pc A principal components Matrix. Each column is one principal component.
* @param explainedVariance A vector of proportions of variance explained by
* each principal component.
*/
@Experimental
class PCAModel private[ml] (
......
......@@ -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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment