python - 带有百分位数的 ROC 曲线
问题描述
我想绘制 ROC 曲线(假阳性率与中值真阳性率)以及两个范围:
- 高分位数范围(高分位数 TPR 与 FPR),例如 85% 分位数
- 低分位数范围(低分位数 TPR 与 FPR),例如 25% 分位数
我的误报率定义为:
def false_positive_rate(preds, targets):
preds = np.array(preds)
targets = np.array(targets)
ids = np.argsort(-preds)
sorted_targets = targets[ids]
P = np.sum(targets == 1)
N = np.sum(targets != 1)
FPR = np.cumsum(1 - sorted_targets)/N
return FPR
真阳性率:
def true_positive_rate(preds, targets):
preds = np.array(preds)
targets = np.array(targets)
ids = np.argsort(-preds)
sorted_targets = targets[ids]
P = np.sum(targets == 1)
N = np.sum(targets != 1)
TPR = np.cumsum(sorted_targets)/P
return TPR
计算 FPR、高、低和中 TPR:
probs = clf.predict_proba(X_test)
probs = probs[:, 1]
num = 100
scores_list = []
for n in range(num):
clf = train_func(X_train, y_train, param)
probs = score_func(X_test, clf)
scores_list.append(probs)
fpr = false_positive_rate(scores_list, y_test)
tpr_low = true_positive_rate_func(np.percentile(scores_list, 25, axis=0), y_test)
tpr_mid = true_positive_rate_func(np.percentile(scores_list, 50, axis=0), y_test)
tpr_high = true_positive_rate_func(np.percentile(scores_list, 85, axis=0), y_test)
这是计算百分位数的正确方法吗?我没有得到想要的 ROC 图。
解决方案
推荐阅读
- javascript - 仅当子元素存在时隐藏元素
- elasticsearch - 弹性搜索索引上的多个分析器
- database - 将 Postgres DB 中的 2 个模式与不同的飞行路径合并
- javascript - 我需要一些帮助来验证 javascript 中的以下代码
- javascript - 需要帮助修改 skew.js 以进行 Y 轴旋转
- amazon-web-services - 在下面的 json 输出中使用 jq 时出现解析错误
- sql - 如何显示教师教 DBMS 系学生的系列表?
- python - 从元组列表中查找与用户输入对应的值
- google-bigquery - 数据流 SQL - 不支持的类型地理
- c# - MathNET.Numerics 中 Matlab unique() 的等效功能?