当前位置:网站首页>统计偏科最严重的前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)
}
}
边栏推荐
- 十分钟带你入门Nodejs
- liunx下mysql遇到的简单问题
- MySQL知识总结 (三) 索引
- redis delay queue
- 数据乱码问题—更改mysql字符编码
- YOLOv7 uses cloud GPU to train its own dataset
- Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id ‘c
- C语言初级—常见问题(100~200素数,计算1+11+111+...,从键盘获取一个数并输出有几个位)
- The specific operation process of cloud GPU (Hengyuan cloud) training
- 线性代数期末复习存档
猜你喜欢
随机推荐
Unit 13 Mixing in View Base Classes
verilog学习|《Verilog数字系统设计教程》夏宇闻 第三版思考题答案(第九章)
C语言日记 4 变量
Briefly write about the use and experience of PPOCRLabel
标签加id 和 加号 两个文本框 和一个var 赋值
VS Code远程开发及免密配置
十分钟带你入门Nodejs
uniCloud 未能获取当前用户信息:30205 | 当前用户为匿名身份
Unit 11 Serializers
drf serializer - Serializer
存储系统Cache(知识点+例题)
宝塔搭建PHP自适应懒人网址导航源码实测
宝塔面板搭建小说CMS管理系统源码实测 - ThinkPHP6.0
c语言三子棋详解!!! (电脑智能下棋)(附上完整代码)
[ROS] Introduction to common tools in ROS (to be continued)
VS Code无法安装插件之Unable to install because, the extension '' compatible with current version
每周招聘|PostgreSQL专家,年薪60+,高能力高薪资
使用云GPU+pycharm训练模型实现后台跑程序、自动保存训练结果、服务器自动关机
主存储器(一)
华为防火墙IPS