title: Trouble understanding MLlib PCA output in Spark (Scala)
body: <p>I am trying to run PCA on a small sample dataset using the Spark MLlib RowMatrix library, and am getting a different matrix output than when I run PCA using other programs (Excel and Weka). The code I am using:</p>
  
  <pre><code>val rows = textFile.map { line =&gt;
  val values = line.split(",").map(_.toDouble) 
  Vectors.dense(values)
  val mat = new RowMatrix(rows)
  val pc: Matrix = mat.computePrincipalComponents(mat.numCols().toInt)
  val c = mat.multiply(pc) 
  println(pc)
  </code></pre>
  
  <p>Here is the input dataset (textFile):</p>
  
  <pre><code>4, 0, 6
  16, 8, 2
  12, 4, 1
  0, 3, 12
  1, 5, 18
  2, 8, 14
  </code></pre>
  
  <p>And the output:</p>
  
  <pre><code>-0.690617646131419    -0.42474982540272854  0.585350196610755    
  -0.04140208648197004  -0.7848198589261455   -0.6183394345099498  
  0.7220340255741673    -0.4512708442338108   0.5244249146042417
  </code></pre>
  
  <p>However, the output when I run PCA on excel/weka is:</p>
  
  <pre><code>0.717   -0.081  0.692
  0.191   -0.932  -0.308
  -0.67   -0.353  0.653
  </code></pre>
  
  <p>I believe the outputs in both cases are related to the contribution of each column of the original dataset to the new principle component columns (and know I can multiply these components by the original data to get projections along the new principle component axes), but am unsure why the outputs are different when using different platforms to perform PCA. </p>
  
  <p>Can anyone explain why Spark is producing a different PCA output matrix? In addition, is there any way to convert this output matrix to eigenvectors/values?</p>
  
  <p>Thanks</p>