php - PHP TNTClassifier似然概率分布
问题描述
我正在使用 TNT 搜索文本分类模块 https://github.com/teamtnt/tntsearch,它运行良好,问题是我不知道如何解释结果 - 更具体地说是正确匹配的可能性。我读过它使用朴素贝叶斯分类器,但我无法找到结果是哪种概率分布。我有自己的大约 50 个值(50 / 10 = 5 个类别)的小型测试数据集,并且猜测相当正确。
但是,此工具提供的似然数是大约 -15 到 -25 范围内的负数。
问题是,什么值可以被解释为不可信?假设该工具只有 <33% 的把握。这个假设对应的值是多少?
解决方案
我已经与 TNTSearch 开发人员取得了联系。分类器实际上并没有返回一个概率,而是一个“最高分”。并且只为最好的匹配。
按照建议,我对代码进行了一些更改。
在课堂TeamTNT\TNTSearch\Classifier\TNTClassifier
上,我更改了predict
方法中的位(softmax 函数灵感来自这里):
public function predict($statement)
{
$words = $this->tokenizer->tokenize($statement);
$best_likelihoods = [];
$best_likelihood = -INF;
$best_type = '';
foreach ($this->types as $type) {
$best_likelihoods[$type] = -INF;
$likelihood = log($this->pTotal($type)); // calculate P(Type)
$p = 0;
foreach ($words as $word) {
$word = $this->stemmer->stem($word);
$p += log($this->p($word, $type));
}
$likelihood += $p; // calculate P(word, Type)
if ($likelihood > $best_likelihood) {
$best_likelihood = $likelihood;
$best_likelihoods[$type] = $likelihood;
$best_type = $type;
}
}
return [
'likelihood' => $best_likelihood,
'likelihoods' => $best_likelihoods,
'probability' => $this->softmax($best_likelihoods),
'label' => $best_type
];
}
然后可以在 中找到百分比概率$guess['probability']['$label']
。
推荐阅读
- python - NoReverseMatch at / UpdateView
- python - 如何将多处理队列从 tkinter 类转移到工作类/函数
- windows - powershell 以管理员身份启动进程,我错过了什么
- php - 对象数组,按日期排序
- asp.net-core - 如何通过身份中的 id 获取用户名?
- django - 为什么在 django admin 中设置初始字段值不起作用?
- javascript - JS:replace不是替换信息
- python - 缺少 Dask.array.ghost 属性
- css - 菜单不会全屏显示
- postgresql - postgresql 中的随机慢查询