这里是解决方法:读取您的数据框(在下面的代码中,将Check列视为int(而不是布尔值),并按增加confidence的顺序进行排序。
现在在将置信度阈值扫描到各行时查看这些值:[ round(df.iloc[n:].Check.mean(), 3) for n in range(len(df.index))]即为[0.8, 0.889, 0.875, 0.857, 0.833, 0.8, 1.0, 1.0, 1.0, 1.0]
在找到截止行n的编号后,df.iloc[n].confidence为您提供了截止置信度值,该值提供> = 0.95的精度。因此,您可以选择截止置信度阈值作为df.iloc[n-1].confidence ... df.iloc[n].confidence]之间的任何数字
代码:import pandas as pd
dat = """confidence Check
1 TRUE
0.72 TRUE
0.68 TRUE
1 TRUE
0.150287157 FALSE
1 TRUE
0.7 TRUE
0.68 TRUE
1 TRUE
0.903333333 FALSE"""
df = pd.read_csv(pd.compat.StringIO(dat), header=0, delim_whitespace=True, dtype={'confidence':'float', 'Check':'int'})
df.sort_values(by='confidence', inplace=True)
df
confidence Check
4 0.150287 0
2 0.680000 1
7 0.680000 1
6 0.700000 1
1 0.720000 1
9 0.903333 0
0 1.000000 1
3 1.000000 1
5 1.000000 1
8 1.000000 1
# Sweep over the df, finding the cutoff row which gives us 0.95 confidence...
for n in range(len(df.index)):
if df.iloc[n:].Check.mean() >= 0.95:
break
# ...then find the range for the cutoff confidence level
print("Cutoff confidence level is between:", df.iloc[n-1].confidence, df.iloc[n].confidence)
# Cutoff confidence level is between: 0.903333333 1.0