0
我创建了一个模型,在其中运行朴素贝叶斯以获得预期的输出。在python中使用naive bayes的文本分类
from textblob.classifiers import NaiveBayesClassifier as NBC
from textblob import TextBlob
training_corpus = [
('Agree Completely Agree Strongly Agree Somewhat Disagree Somewhat Disagree Strongly Completely Disagree','TRUE'),
('Concerned 2 3 4 5 6 7 - Comfortable','TRUE'),
('1 - disagree strongly 2 - disagree somewhat 3 - neither agree nor disagree 4 - agree somewhat 5 - agree strongly','TRUE'),
('1 - doesn\'t apply at all 2 3 4 5 6 7 - applies completely','TRUE'),
('1 - extremely new and different 2 3 4 5 6 7 - not at all new & different','TRUE'),
('1 - extremely relevant 2 3 4 5 6 7 - not at all relevant','TRUE'),
('1 - I don\'t want brands to engage with me at all on social media 2 3 4 5 6 7 - I love to engage with brands on social media','TRUE'),
('1 - Most Important 2 3 4 5 - Least Important','TRUE'),
('pepsi','FALSE'),
('coca cola','FALSE'),
('hyundai','FALSE'),
('Audio quality','FALSE'),
('Product features ','FALSE'),
('Content ','FALSE')
]
test_corpus = [
('1 - Agree Completely 2 - Agree Strongly 3 - Agree Somewhat 4 - Disagree Somewhat 5 - Disagree Strongly 6 - Completely Disagree','TRUE'),
('1 - Concerned 2 3 4 5 6 7 - Comfortable','TRUE'),
('Content ','FALSE'),
('Ease of navigation','FALSE')
]
model = NBC(training_corpus)
print(model.classify('pepsi'))
print(model.accuracy(test_corpus)*100)
当我运行此代码时,它显示100%的效率,但每次都返回FALSE。我不确定什么是错的,但那不是预期的输出。
谢谢伊曼...我的工作就可以了,将让你知道,如果有有任何问题。 –
不客气:) –