简体   繁体   中英

Spark Scala MLlib assignment syntax

I've been going through the guide at https://spark.apache.org/docs/latest/ml-statistics.html and I've noticed that they're using this syntax for val assignment:

val Row(coeff1: Matrix) = Correlation.corr(df, "features").head

Can someone elaborate on what this means? It seems similar to how Scala handles regex group extraction...

It is nothing more than a pattern matching . To make it more obvious, you rewrite it as:

val coeff1 = Correlation.corr(df, "features").head match {
  case Row(coeff1: Matrix) => coeff1
}

In other words it just tries to match the object returned form .head call and on successful match, it creates a reference ( coeff1 ) to the Matrix object contained in the returned Row .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM