TextBlob模块中还有另一个分类器,称为PositiveNaiveBayesClassifier。引用他们的文档:
朴素贝叶斯分类器的一种变体,它使用部分标记的训练集执行二元分类,即当只有一个类被标记而另一个没有被标记时。假设两个标签上的先验分布,使用未标记的集合来估计特征的频率。
代码用法:
>>> from text.classifiers import PositiveNaiveBayesClassifier
>>> sports_sentences = ['The team dominated the game',
'They lost the ball',
'The game was intense',
'The goalkeeper catched the ball',
'The other team controlled the ball']
>>> various_sentences = ['The President did not comment',
'I lost the keys',
'The team won the game',
'Sara has two kids',
'The ball went off the court',
'They had the ball for the whole game',
'The show is over']
>>> classifier = PositiveNaiveBayesClassifier(positive_set=sports_sentences,
unlabeled_set=various_sentences)
>>> classifier.classify("My team lost the game")
True
>>> classifier.classify("And now for something completely different.")
False