Q: Calculating Dunn Index in Spark Scala I am trying to calculate Dunn Index to measure my performance of my Kmeans Cluster on the below dataset. 
         V1            V2            V3          V4          V5        
   -0.80688767  2.580938e-01 -2.310133e-01 -0.69172608  0.76195996  
   -0.80871432  5.357830e-01 -2.320617e-01 -1.09496541  0.71935607  
   -0.79147152 -6.051847e-01 -9.574660e-02 -1.02494869  0.89793288  
   -0.77096829 -1.859497e+00 -4.956332e-01 -0.77016532  1.20462390  
   -0.67800192 -1.595468e+00 -7.405667e-01 -0.89351545  0.92360485  
   -0.62255535  1.167977e+00 -1.656397e-01 -0.59319708  1.20205692  
   -0.81017300 -1.234912e+00 -5.714762e-01 -0.86877635  0.32971553  
   -0.72079901  5.085883e-01 -5.726607e-01 -0.91749111  0.46749543  
   -0.87377368 -5.650047e-01 -1.437415e-01 -0.65893811  0.61737109  

Below is my code to calculate Dunn Index.
import org.apache.spark.mllib.clustering.KMeans

import org.apache.spark.{SparkConf, SparkContext}

import org.apache.spark.mllib.linalg.{Vector, Vectors}

import org.apache.spark.rdd.RDD

val sc = spark.sparkContext

val data = sc.textFile("/FileStore/tables/sample.csv", 16)

val dataRDD = data
      .map(s => s.split(",")
        .map(_.toDouble))
      .keyBy(_.apply(0))
      .cache()

val parsedData = dataRDD.map(s => Vectors.dense(s._2)).cache()

val clusters = KMeans.train(parsedData,2,100)

//Global Center
val centroides = sc.parallelize(clusters.clusterCenters)

val centroidesCartesian = centroides.cartesian(centroides).filter(x => x._1 != x._2).cache()

// DUNN

val minA = centroidesCartesian.map(x => Vectors.sqdist(x._1, x._2)).min()

val maxB = parsedData.map( r => Vectors.sqdist(r, clusters.clusterCenters(clusters.predict(r)))).max

//Get Dunn index
val dunn = minA / maxB

I am getting a error while calculating "maxB".
Error is "org.apache.spark.SparkException: Task not serializable". 
This is the line of code that produces the error
val maxB = parsedData.map( r => Vectors.sqdist(r, clusters.clusterCenters(clusters.predict(r)))).max
Any idea how to resolve this? 
Also, I am open to knowing if there is a better way to calculate Dunn Index in Spark Scala?
