MAX and MIN value of RDD[scala.collection.immutable.Map[String,Any]
<p>in the following code I calculate the euclidean distance for each document to the cluster centroid in a KMeans cluster.
I feel like the euclidean distance does not make much sense so I thought normalizing it to a scale from from 0 to 1 would be better.</p>

<p>Unfortunately, I didn't figure out how to sort the <code>org.apache.spark.rdd.RDD[scala.collection.immutable.Map[String,Any]]</code> data type or how to get the maximum / minimum value. </p>

<p>In fact it is a <code>RDD[Map[String,Double]]</code> but I suppose it got converted to an <code>RDD[Map[String,Any]]</code> for some reason. Most approaches e.g <code>takeOrdered</code> results in:</p>

<blockquote>
  <p>error: No implicit Ordering defined for scala.collection.immutable.Map[String,Any]</p>
</blockquote>

<p>How can I teach Scala how to sort the Any values of this Map?
Any hints are very much appreciated.</p>

<p>Thanks</p>

<pre><code>val score = rdd.map({case(id,vector) =&gt; {distToCentroid(id, vector, model_1)}})

// Normalizing the data with normalizeResult function.
// Problem I need to find the max and minimum beforehand        
def distToCentroid(id: String, datum: Vector, model: KMeansModel) = {
  val cluster = model.predict(datum)
  val centroid = model.clusterCenters(cluster)
  val distance = math.sqrt(centroid.toArray.zip(datum.toArray).map(p =&gt; p._1 - p._2).map(d =&gt; d * d).sum)
  Map("id" -&gt; id, "distance" -&gt; distance)
}

def normalizeResult(max: Double, min: Double, x: Double) = { 
  (x-min) / (max-min)
}
</code></pre>