sql 计算auc

https://tracholar.github.io/machine-learning/2018/01/26/auc.html

select
    (ry - 0.5*n1*(n1+1))/n0/n1 as auc
from(
    select
        sum(if(y=0, 1, 0)) as n0, --50
        sum(if(y=1, 1, 0)) as n1,--100
        sum(if(y=1, r, 0)) as ry --100
    from(
        select y, row_number() over(order by score asc) as r
        from(
            select y, score
            from some.table
        )A
    )B
)C

posted @ 2019-04-02 18:39  change_world  阅读(2278)  评论(0编辑  收藏  举报