gpt4 book ai didi

python - 我如何重新采样 "roc_curve"(fpr,tpr)?

转载 作者:太空宇宙 更新时间:2023-11-04 05:49:47 25 4
gpt4 key购买 nike

我希望对“roc_curve”(sklearn) 输出重新采样。

当我在 Ipython 中绘制 fpr,tpr 时很好,但有时我想导出它(主要是为客户端),但很难理解,因为它不是线性的。

例如

fpr =[0,0.1,0.4,0.9,1]
tpr =[0,0.3,0.4,0.5,1]

我如何将 fpr 重新采样为每 5% ex 线性:

[0,0.05,0.1,0.15,0.2,0.25,0.3,0.35,0.4,0.45,0.5,0.55,0.6,0.65,0.7,0.75,0.,0.85,0.9,0.95,1]

tpr:

[0,0.15,0.3,0.3167,0.333,0.35,0.3667,0.383,0.4,0.41,0.42,0.43,0.44,0.45,0.46,0.47,0.48,0.49,0.5,0.75,1]

我该如何继续?

最佳答案

我认为您正在寻找的是分段常数插值。

import numpy as np
from scipy.interpolate import spline

fpr =[0,0.1,0.4,0.9,1]
tpr =[0,0.3,0.4,0.5,1]

n = 20
x_interp = np.linspace(0,1,n+1)
y_interp = spline(fpr, tpr, x_interp, order=0)

x_interpfpr

[ 0.    0.05  0.1   0.15  0.2   0.25  0.3   0.35  0.4   0.45  0.5   0.55
0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1. ]

y_interp 是对应的tpr

[ 0.   0.   0.3  0.3  0.3  0.3  0.3  0.3  0.4  0.4  0.4  0.4  0.4  0.4  0.4
0.4 0.4 0.4 0.5 0.5 0.5]

关于python - 我如何重新采样 "roc_curve"(fpr,tpr)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30802688/

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