Github user jkbradley commented on a diff in the pull request:
https://github.com/apache/spark/pull/7522#discussion_r36045312
--- Diff: docs/ml-features.md ---
@@ -461,6 +461,87 @@ for binarized_feature, in binarizedFeatures.collect():
</div>
</div>
+## PCA
+
+[PCA](http://en.wikipedia.org/wiki/Principal_component_analysis) is a
statistical procedure that uses an orthogonal transformation to convert a set
of observations of possibly correlated variables into a set of values of
linearly uncorrelated variables called principal components. A
[PCA](api/scala/index.html#org.apache.spark.ml.feature.PCA) class trains a
model to project vectors to a low-dimensional space using PCA. The example
below shows how to project 5-dimensional feature vectors into 3-dimensional
principal components.
+
+<div class="codetabs">
+<div data-lang="scala" markdown="1">
+{% highlight scala %}
+import org.apache.spark.ml.feature.PCA
+import org.apache.spark.mllib.linalg.Vectors
+
+val data = Array(
+ Vectors.sparse(5, Seq((1, 1.0), (3, 7.0))),
+ Vectors.dense(2.0, 0.0, 3.0, 4.0, 5.0),
+ Vectors.dense(4.0, 0.0, 0.0, 6.0, 7.0)
+)
+val df =
sqlContext.createDataFrame(data.map(Tuple1.apply)).toDF("features")
+val pca = new PCA()
+ .setInputCol("features")
+ .setOutputCol("pcaFeatures")
+ .setK(3)
+ .fit(df)
+val pcaDF = pca.transform(df)
+val result = pcaDF.select("pcaFeatures")
+result.show()
+{% endhighlight %}
+</div>
+
+<div data-lang="java" markdown="1">
+{% highlight java %}
+import com.google.common.collect.Lists;
--- End diff --
Just to confirm: Did you run the Java example?
The example should import PCA, PCAModel (since we should not assume it's in
the same namespace).
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]