所以,我正在尝试进行文本多类分类。我阅读了很多旧的问题和博客文章,但仍然无法完全理解这个概念。
我也尝试了这个博客文章中的一些例子。 http://www.laurentluce.com/posts/twitter-sentiment-analysis-using-python-and-nltk/
但当涉及到多类分类时,我不太理解。假设我想将文本分类为多种语言,法语、英语、意大利语和德语。我想使用NaviesBayes,因为我认为这将是最容易开始的。从我读过的旧问题来看,最简单的解决方案是使用一对多的方法。因此,每种语言将有自己的模型。所以,我将为法语、英语和意大利语准备3个模型。然后我会将一段文本与每个模型进行对比,并检查哪个模型的概率最高。我的理解正确吗?
但在编码时,上面的例子中他有这样的推文,这些推文将被分类为正面或负面。
pos_tweets = [('I love this car', 'positive'), ('This view is amazing', 'positive'), ('I feel great this morning', 'positive'), ('I am so excited about tonight\'s concert', 'positive'), ('He is my best friend', 'positive')]neg_tweets = [('I do not like this car', 'negative'), ('This view is horrible', 'negative'), ('I feel tired this morning', 'negative'), ('I am not looking forward to tonight\'s concert', 'negative'), ('He is my enemy', 'negative')]
这些是正面或负面的。所以,当训练法语的一个模型时,我应该如何标记文本?会是这样的吗?那么这将是正面的吗?
[('Bon jour', 'French'), 'je m'appelle', 'French']
而负面的是
[('Hello', 'English'), ('My name', 'English')]
但这是否意味着我可以只添加意大利语和德语,并为4种语言使用一个模型?或者我真的不需要负面的?
所以,问题是使用ntlk进行多类分类的正确方法是什么?
回答:
使用Naive Bayes不需要一对多的方案——它本身就是一个多类模型。只需向分类器学习器提供一个(sample, label)
对的列表,其中label
表示语言即可。