NLTK使用训练有素的分类器对界面进行分类 [英] NLTK classify interface using trained classifier

查看:213
本文介绍了NLTK使用训练有素的分类器对界面进行分类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只有一小段代码但是我该如何对语料库中可能存在的随机单词进行分类.

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?

非常感谢您.

感谢@unutbu的反馈和一些发掘的

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆