Python TextBlob朴素贝叶斯文本分类
我正在尝试使用python中的TextBlob在tweet上实现NaiveBayes分类器。我已经能够对数据集进行培训,并能够使用以下方法成功地对个人推文进行分类:Python TextBlob朴素贝叶斯文本分类,python,text-classification,textblob,Python,Text Classification,Textblob,我正在尝试使用python中的TextBlob在tweet上实现NaiveBayes分类器。我已经能够对数据集进行培训,并能够使用以下方法成功地对个人推文进行分类: print cl.classify("text") 现在我想打开一个csv文件,并对该文件中的所有推文进行分类。对我如何实现这一目标有什么建议吗?我的代码如下: import csv from textblob import TextBlob with open(test_path, 'rU') as csvfile:
print cl.classify("text")
现在我想打开一个csv文件,并对该文件中的所有推文进行分类。对我如何实现这一目标有什么建议吗?我的代码如下:
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”对象没有属性“classify”您也需要先进行训练(不清楚您是否已经这样做了?)
你也需要先进行训练(不清楚你是否已经这样做了?)
您正在调用
list
上的classify()
。您应该对blob
执行此操作。为什么有两个读线器作业?感谢您提供的解决方案!您正在调用list
上的classify()
。您应该对blob
执行此操作。为什么有两个读线器作业?感谢您提供的解决方案!
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)