NLTK使用训练有素的分类器对界面进行分类 [英] NLTK classify interface using trained classifier
问题描述
我只有一小段代码但是我该如何对语料库中可能存在的随机单词进行分类.
But how can I classify a random word that might be in the corpus.
classifier.classify('magnificent')
不起作用.它需要某种物体吗?
Doesn't work. Does it need some kind of object?
非常感谢您.
Thanks to @unutbu's feedback and some digging here and reading the comments on the original post the following yields 'pos' or 'neg' for this code (this one's a 'pos')
print(classifier.classify(word_feats(['magnificent'])))
这将得出单词"pos"或"neg"的评估结果
and this yields the evaluation of the word for 'pos' or 'neg'
print(classifier.prob_classify(word_feats(['magnificent'])).prob('neg'))
推荐答案
print(classifier.classify(word_feats(['magnificent'])))
收益
pos
classifier.classify
方法本身并不针对单个单词进行操作,而是基于功能的dict
进行分类.在此示例中,word_feats
将句子(单词列表)映射到特征的dict
.
The classifier.classify
method does not operate on individual words per se, it classifies based on a dict
of features. In this example, word_feats
maps a sentence (a list of words) to a dict
of features.
这是另一个示例(来自NLTK书),它使用NaiveBayesClassifier
.通过比较该示例与您发布的示例之间的相似之处和不同之处,您可以更好地了解其用法.
Here is another example (from the NLTK book) which uses the NaiveBayesClassifier
. By comparing what is similar and different between that example, and the one you posted, you may get a better perspective of how it can be used.
这篇关于NLTK使用训练有素的分类器对界面进行分类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!