gpt4 book ai didi

python - ctr预测中计算auc的这段代码是什么意思?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:18:19 26 4
gpt4 key购买 nike

请原谅我蹩脚的英语。这是代码。

def scoreClickAUC(num_clicks, num_impressions, predicted_ctr):  
"""
Calculates the area under the ROC curve (AUC) for click rates

Parameters
----------
num_clicks : a list containing the number of clicks

num_impressions : a list containing the number of impressions

predicted_ctr : a list containing the predicted click-through rates

Returns
-------
auc : the area under the ROC curve (AUC) for click rates
"""
i_sorted = sorted(range(len(predicted_ctr)),key=lambda i: predicted_ctr[i],
reverse=True)
auc_temp = 0.0
click_sum = 0.0
old_click_sum = 0.0
no_click = 0.0
no_click_sum = 0.0

# treat all instances with the same predicted_ctr as coming from the
# same bucket
last_ctr = predicted_ctr[i_sorted[0]] + 1.0

for i in range(len(predicted_ctr)):
if last_ctr != predicted_ctr[i_sorted[i]]:
auc_temp += (click_sum+old_click_sum) * no_click / 2.0
old_click_sum = click_sum
no_click = 0.0
last_ctr = predicted_ctr[i_sorted[i]]
no_click += num_impressions[i_sorted[i]] - num_clicks[i_sorted[i]]
no_click_sum += num_impressions[i_sorted[i]] - num_clicks[i_sorted[i]]
click_sum += num_clicks[i_sorted[i]]
auc_temp += (click_sum+old_click_sum) * no_click / 2.0
auc = auc_temp / (click_sum * no_click_sum)
return auc

我对段落“(click_sum+old_click_sum) * no_click/2.0”的含义感到困惑。请帮助我。

最佳答案

当多个点具有完全相同的预测分数时,曲线下的区域是线性插值

您看到的方程是切片的面积,如下所示:

   /
/|
/ |
/ |
| |
| |
+--+

这个的面积可以计算为平均高度 * 宽度 = (height_left+height_right)+width/2

关于python - ctr预测中计算auc的这段代码是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40418167/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com