文字Blob朴素贝叶斯分类

时间:2018-02-19 06:13:17

标签: python naivebayes textblob

我正在使用textblob lib进行分类,使用朴素的贝叶斯,我有一套火车,我想检查一下我是否应该在火车上检查一个字,并进行相应的分类,如果火车中没有该字,则不应该建议任何分类。

示例:kartik不在火车组中,但是它将其分类为“1”,对于训练集中不存在的任何其他单词也是如此。

如果我建议一些不在列车中的单词不应该给'1',有什么办法。

from textblob import TextBlob
from textblob.classifiers import NaiveBayesClassifier


train = [
 ('System is working fine', '1'),
 ('Issue Resolved ', '1'),
 ('Working Fine ', '1'),
 ('running smoothly', '1'),
 ("server is working fine ", '1'),
 ('software installed properly', '1'),
 ('Ticket resolved ', '1'),
 ("Laptop is not working ", '-1'),
 ('laptop issue', '-1'),
 ('upgrade laptop', '-1'),
 ('software not working','-1'),
 ('fix the issue','-1'),
 ('WIFI is not working','-1'),
 ('server is down','-1'),
 ('system is not working','-1')


]

c1 = NaiveBayesClassifier(train)
c1.classify("kartik")

1 个答案:

答案 0 :(得分:0)

您可以尝试使用获取分类概率,然后设置一个阈值,忽略给定的下面的类标签。

prob_dist = cl.prob_classify("Lorem Ispum dolor sit amet")
cl.classify("Lorem Ipsum Dolor sit amet")
print(round(prob_dist.prob("1"), 2))
print(round(prob_dist.prob("-1"),2))
  

0.61

     

0.39

我观察到所有不存在的单词在第1课时的概率为0.61。您可以将此作为起点。

但是,请正确测试所有正确的情况。设置阈值可能会对某些正确的分类产生不利影响。

无论如何,增加列车数据的大小,您会看到更好的结果,这可以帮助您设置阈值