Spark上如何做分布式AUC计算

本文介绍了在Spark中如何进行分布式AUC计算,特别是在实际应用中,针对(label, predict_score)形式的数据,使用名为BinaryAuc的近似计算方法。该方法通过对predict_score排序,计算每个小梯形的面积,最后汇总得出AUC值。由于数据以分布式RDD形式存在,需要遍历数据获取前一个RDD的offset,以避免单机汇总。" 129332728,17585464,Java实现的物品交换平台设计与实现,"['Java开发', 'Web应用', '数据库设计', '课程设计', 'Mybatis框架']

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

by 王犇 20160115

AUC是分类模型常用的评价手段,目前的Spark mllib里面evaluation包中所提供的auc方法是拿到了roc曲线中的各个点之后再进行auc的计算,但是实际应用场景中(以逻辑回归为例),我们常常是对每个样本进行打分之后整合样本的label直接进行auc的计算,输入可能是(label, predict_score)这样的形式,mllib中提供的方案就不太适用了,所以这里提供了另一种计算方法,采用了针对0,1分类问题的近似计算方案,叫做BinaryAuc:

首先对predict_score进行排序,然后根据样本正负例的情况,分别计算每个小梯形的面积,最后汇总成为最终的auc值(由于在spark中数据是分布式RDD的形态,所以计算梯形面积的时候需要知道前一个RDD的offset,这里需要先遍历数据,但是避免了汇总到单机进行计算):

package org.apache.spark.mllib.wml

/**
 * @author wangben 2015
 */
import org.apache.spark.SparkContext
import org.apache.spark.SparkConf
import org.apache.spark.rdd.RDD
import org.apache.spark.mllib.rdd.RDDFunctions._
import scala.collection.Iterator
import Array._

class BinaryAUC extends Serializable {
  //input format: predictioin,label
  def auc( data: RDD[ (Double, Double) ] ) : Double =
  {
    //group same score result
    val group_result = data.groupByKey().map(x => {
      var r = new Array[Double](2)
      for(item <- x._
Build machine learning models, natural language processing applications, and recommender systems with PySpark to solve various business challenges. This book starts with the fundamentals of Spark and its evolution and then covers the entire spectrum of traditional machine learning algorithms along with natural language processing and recommender systems using PySpark. Machine Learning with PySpark shows you how to build supervised machine learning models such as linear regression, logistic regression, decision trees, and random forest. You'll also see unsupervised machine learning models such as K-means and hierarchical clustering. A major portion of the book focuses on feature engineering to create useful features with PySpark to train the machine learning models. The natural language processing section covers text processing, text mining, and embedding for classification. After reading this book, you will understand how to use PySpark's machine learning library to build and train various machine learning models. Additionally you'll become comfortable with related PySpark components, such as data ingestion, data processing, and data analysis, that you can use to develop data-driven intelligent applications. What You Will Learn Build a spectrum of supervised and unsupervised machine learning algorithms Implement machine learning algorithms with Spark MLlib libraries Develop a recommender system with Spark MLlib libraries Handle issues related to feature engineering, class balance, bias and variance, and cross validation for building an optimal fit model Who This Book Is For Data science and machine learning professionals.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值