Category Archives: apache-spark-ml

Spark & Scala MultilayerPerceptronClassifier – java.lang.NegativeArraySizeException

I am running to a "NegativeArraySizeException" error when I try to train a MultilayerPerceptronClassifier model in Spark Scala. I am following the example found here. Below is my code - I am aware that the layers typically go from large to small and that they are in reverse here - this is experimental but I have found nothing in the docs that explicitly prevent it.

// Data in
var df="delimiter", "|").option("inferSchema", "true").format("csv").load("hdfs://master-node:9000//example.csv")

// Split the data into train and test
val splits = df.randomSplit(Array(0.9, 0.1))
val train = splits(0)
val test = splits(1)

// Set input dimensions
val input_dim = 3072
val output_dim = 198000

// Specify layers
val layers = Array[Int](input_dim, 24777, 49555, output_dim)

// create the trainer and set its parameters
val trainer = new MultilayerPerceptronClassifier().setLayers(layers).setBlockSize(128).setSeed(1234L).setMaxIter(100).setFeaturesCol("features").setLabelCol("label")

// train the model
val model =

The error is thrown upon "" The data is is the same format as the example where labels = Double and data = Vector.

Here is the error, any familiarly with it?

scala> val model =
  at scala.reflect.ManifestFactory$$anon$12.newArray(Manifest.scala:141)
  at scala.reflect.ManifestFactory$$anon$12.newArray(Manifest.scala:139)
  at breeze.linalg.DenseVector$.zeros$mDc$sp(DenseVector.scala:254)
  ... 52 elided