我正在进行一个说话人识别项目,我已经训练了模型,其精度为90%,但我在进行推理时遇到了一个问题,模型给出了两个概率,因为它是为两个对话者训练的,但我希望当我检测到一个不在训练集中的说话人时,告诉我他是“未知说话人”,因此,如何根据模型给出的两种概率选择决策阈值
这是有问题的代码片段:
sample_df = pd.DataFrame(list_).transpose()
sample_pred = model.predict(sample_df)[0] # Here the model returns the name of the
# predicted speaker
sample_prob = model.predict_proba(sample_df)[0] # Here I get a list of two items, the
# probabilities for each speaker
print(sample_prob) # Output example: [0.46 0.54]
for k,j in enumerate(sample_prob):
if j <= 0.6 and sample_prob[k+1] <= 0.6: # How to change dynamically according to the
# result of sample_prob, this threshold ?,
# for example I put 0.6.
sample_pred= "unknown speaker"
break
else:
break
我认为您有一个二进制分类任务->;它是否是一个“未知说话人”。而且,如果我理解正确,您希望优化阈值。换句话说,您不希望使用0.5。由于这是一项分类任务,我将选择使验证集(而不是测试集)上的
f1-score
最大化的阈值,因为这意味着存在数据泄漏:最佳分数由
thresholds[idx]
给出我看到你输出了2个概率,但你真的只需要一个。从第一个你可以很容易地推断出第二个
相关问题 更多 >
编程相关推荐