打印最佳截止值时出错/类型错误:不支持操作数类型



我有三个列表:

FPR=[1.0,0.6437673130193906,0.22105263157894736,0.03102493074792244,0.00221606648199446,0.0]
TPR=[1.0,0.9407831900668577,0.7172874880611271,0.3638968481375358,0.10315186246418338,0.0]
thresholds=array([0. , 0.2, 0.4, 0.6, 0.8, 1. ])

我正在尝试检索最佳截止值。我试过下面的代码。

i = np.arange(len(TPR))
roc = pd.DataFrame({'tf' : pd.Series(FPR-(1-FPR), index=i), 'threshold' : pd.Series(thresholds,index=i)})
roc_th = roc.iloc[(roc.tf-0).abs().argsort()[:1]]

但我在第2行中的错误

TypeError: unsupported operand type(s) for -: 'int' and 'list'

请帮我解决这个问题。请让我知道我是否可以为您提供任何额外的信息。

只需将前两行更改为

FPR=np.array([1.0,0.6437673130193906,0.22105263157894736,0.03102493074792244,0.00221606648199446,0.0])
TPR=np.array([1.0,0.9407831900668577,0.7172874880611271,0.3638968481375358,0.10315186246418338,0.0])

当您在定义数据帧的行执行1-FPR时,您正试图从普通python列表中减去1。这是不支持的,因此您的错误说它不能从int和list中减去-。标量矢量减法仅为numpy数组定义。

相关内容

最新更新