Spark - Principal Component Analysis - PCA requires a number of principal components k >= 1 but was given 0
<p>I'm trying to reduce my dimensionality (I've 120 columns) for that I want to apply PCA method:</p>

<pre><code>val data = sc.textFile("data")

val header = data.first

val rows = data.filter(l =&gt; l != header)

import org.apache.spark.mllib.feature.PCA
import org.apache.spark.mllib.linalg.Vectors
import org.apache.spark.mllib.regression.{LabeledPoint, LinearRegressionWithSGD}

val data = rows.map { line =&gt;
  val parts = line.split(';')
  LabeledPoint(parts(0).toDouble, Vectors.dense(parts(1).split(';').map(_.toDouble)))
}.cache()

val splits = data.randomSplit(Array(0.9, 0.1), seed = 11L)
val training = splits(0).cache()
val test = splits(1)

val pca = new PCA(training.first().features.size / 2).fit(data.map(_.features))
</code></pre>

<p>But I'm getting this error:</p>

<pre><code>java.lang.IllegalArgumentException: requirement failed: PCA requires a number of principal components k &gt;= 1 but was given 0
    at scala.Predef$.require(Predef.scala:233)
    at org.apache.spark.mllib.feature.PCA.&lt;init&gt;(PCA.scala:33)
    at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC.&lt;init&gt;(&lt;console&gt;:59)
</code></pre>

<p>Anyone have an idea why I'm having this issue?</p>

<p>Thanks!</p>