我正在重新取样“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]
我该怎么办?
答案 0 :(得分: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_interp
是fpr
值
[ 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]