我想对“ 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/

10-12 16:31