二分类模型-分布式SPARK效果评估实现代码+混淆矩阵

本文介绍了如何使用Spark进行二分类模型的效果评估,特别关注了在预测值众多时,通过分箱参数降低计算复杂度的策略。官方推荐在计算ROC曲线和PR曲线时,可以设置分箱数量以进行降采样,以减少计算量并保持足够的曲线概括性。通过这种方式,可以确保在处理大规模数据时,依然能有效评估模型性能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近在做一个平台级的项目,为了保证分布式的可扩展性,评估最终用sparkmlib进行模型的评估,sparkmlib里面封装好了二分类、
多分类、聚类的通用的评估指标,通用指标实现起来都比较简单。

关键点:
 val metrics=new BinaryClassificationMetrics(scoreAndLable,100)
  获取到预测列和标签列,并转化为RDD[double,double]。
  • BinaryClassificationMetrics第二个参数解释:这个一个分箱参数,可能你们预测值的不同值会有几百万个,这样会导致计算量巨大,计算的结果也巨大,所以引入分箱,对预测列进行分箱降采样后进行计算。
  • 官方:param: scoreAndLabels an RDD of (score, label) pairs. param: numBins if greater than 0, then the curves (ROC curve, PR curve) computed internally will be down-sampled to this many "bins". If 0, no down-sampling will occur. This is useful because the curve contains a point for each distinct score in the input, and this could be as large as the input itself -- millions of points or more, when thousands may be entirely sufficient to summarize the curve. After down-sampling, the curves will instead be made of approximately numBins points instead. Points are made from bins of equal numbers of consecutive points. The size of each bin is floor(scoreAndLabels.count() / numBins), which means the resulting number of bins may not exactly equal numBins. The last bin in each partition may be smaller as a result, meaning there
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值