[英]TextBlob Naive Bayes text classification
I'm trying to implement the Naive Bayes classifier on tweets using TextBlob in python. 我正在尝试使用python中的TextBlob在推文上实现Naive Bayes分类器。 I have been able to train the dataset and can successfully classify individual tweets using:
我已经能够训练数据集并且可以使用以下方法成功地对单个推文进行分类:
print cl.classify("text")
Now I want to open a csv file and classify all the tweets in that file. 现在我想打开一个csv文件并对该文件中的所有推文进行分类。 Any suggestions on how I can achieve this?
有关如何实现这一目标的任何建议? My code is as below:
我的代码如下:
import csv
from textblob import TextBlob
with open(test_path, 'rU') as csvfile:
lineReader = csv.reader(csvfile,delimiter=',',quotechar="\"")
lineReader = csv.reader(csvfile,delimiter=',')
test = []
for row in lineReader:
blob = (row[0])
blob = TextBlob(blob)
test.append([blob])
print (test.classify())
AttributeError: 'list' object has no attribute 'classify' AttributeError:'list'对象没有属性'classify'
You need to train first too also (not clear if you have done this?), 你也需要先训练(不清楚你是否做过这个?),
train = []
# then repeat your above lines, appending each tweet to train set
# but for a separate training set (or slice up the rows)
# do your test append loop -----
# 1. Now train a model
my_classifier = NaiveBayesClassifier(train)
# 2. test given to the model to get accuracy
accu = my_classifier.accuracy(test)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.