scala map 映射方法

var data = trainData.drop("province").drop("phone_series")
var s1 = data.columns
var map1:Map[Int,String] = Map()
for(i <- 0 until s1.length){
   map1 = map1+(i->s1(i))
}




val labelpoint = chiSqCalculateIndex(data,"persona_id","label")


val topThree = labelpoint.sortWith(_._2 > _._2)
topThree: Array[(Int, Double)] = Array((1,900724.9692090438), (10,224101.55492709286), (4,204211.7910162001), (8,203241.58945527425))




val topThree2 = topThree.map{x=>
  (map1.getOrElse(x._1,""),x._2)


}topThree2: Array[(String, Double)] = Array((hwmovie_watch_duration_sum_mon,900724.9692090438), (hwmovie_pref_watch_period_22_23,224101.55492709286), (hwmovie_pref_watch_period_0_7,204211.7910162001), (hwmovie_pref_watch_period_18_19,203241.58945527425), (hwmovie_pref_watch_period_8_11,202078.15518638666), (hwmovie_pref_watch_period_20_21,186562.70108210688), (hwmovie_pref_watch_period_14_17,176346.94464727934), (hwmovie_pref_watch_period_12_13,172402.11304624344), (hwmovie_pref_categ_series,142332.29776419405), (hwmovie_pref_area_mainland,34192.14323915684), (hwmovie_pref_area_western,27159.010133314583), (hwmovie_pref_area_hktw,24174.931872911897), (hwmovie_pref_categ_documentary,21526.57486590943), (hwmovie_pref_genre_documentary,19378.29537631347), (hwmovie_pref_area_asia,14348.58217...


-------------------------------------------------------------------------

猜你喜欢

转载自blog.csdn.net/weixin_35780812/article/details/78879683