当前位置:网站首页>统计偏科最严重的前100名学生
统计偏科最严重的前100名学生
2022-08-02 14:05:00 【大学生爱编程】
object Demo31Student {
def main(args: Array[String]): Unit = {
//偏科评估的标准: 方差
//1、读取分数
val lines: List[String] = Source.fromFile("data/score.txt").getLines().toList
//2、切分数据
val scoreArr: List[Array[String]] = lines.map(line => line.split(","))
//3、过滤脏数据
val scoreFilter: List[Array[String]] = scoreArr.filter(arr => arr.length == 3)
//4、取出学号和分数
val idAndScore: List[(String, Int)] = scoreFilter.map {
case Array(id: String, _, sco: String) =>
(id, sco.toInt)
}
//5、按照学号分组
val groupBy: Map[String, List[(String, Int)]] = idAndScore.groupBy(kv => kv._1)
//计算方差
val std: List[(String, Double, List[(String, Int)])] = groupBy.map {
case (id: String, list: List[(String, Int)]) =>
//一个学生所有的分数
val scores: List[Int] = list.map { case (_, sco: Int) => sco }
// 计算方差
//1、计算总数 2、计算平均值 3、计算方差
//科目数
val N: Double = scores.length.toDouble
//平均数
val avg: Double = scores.sum / N
//计算方差
val std: Double = scores.map((sco: Int) => (sco - avg) * (sco - avg)).sum / N
(id, std, list)
}.toList
//按照方差排序,取前100
val sortByStd: List[(String, Double, List[(String, Int)])] = std.sortBy(kv => -kv._2)
//取前100
val top10: List[(String, Double, List[(String, Int)])] = sortByStd.take(100)
top10.foreach(println)
}
}
边栏推荐
- drf view component
- uniapp小程序禁止遮罩弹窗下的页面滚动的完美解决办法
- Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id ‘c
- Flask framework
- Unit 8 Middleware
- uni-app页面、组件视图数据无法刷新问题的解决办法
- mysql常用函数
- The language of initial
- St. Regis Takeaway Notes - Lecture 10 Swagger
- YOLOv7使用云GPU训练自己的数据集
猜你喜欢
随机推荐
[VCU] Detailed S19 file (S-record)
verilog学习|《Verilog数字系统设计教程》夏宇闻 第三版思考题答案(第十三章)
无人驾驶综述:摘要
C语言日记 2 标识符
Using the cloud GPU + pycharm training model to realize automatic background run programs, save training results, the server automatically power off
Steps to connect the virtual machine with xshell_establish a network connection between the host and the vm virtual machine
Unit 12 associated serialization
MySQL知识总结 (十) 一条 SQL 的执行过程详解
宏定义问题记录day2
yolov5,yolov4,yolov3 mess
ToF相机从Camera2 API中获取DEPTH16格式深度图
什么是 Web 3.0:面向未来的去中心化互联网
run yolov5
ThinkPHP5.0内置分页函数Paginate无法获取POST页数问题的解决办法
Camera Hal(Hal3)层修改Preview流
C语言日记 4 变量
主存储器(二)
St. Regis Takeaway Notes - Lecture 05 Getting Started with Redis
C语言初级—水仙花数
原码、补码、反码