Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TextBlob朴素贝叶斯文本分类_Python_Text Classification_Textblob - Fatal编程技术网

Python TextBlob朴素贝叶斯文本分类

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:

我正在尝试使用python中的TextBlob在tweet上实现NaiveBayes分类器。我已经能够对数据集进行培训,并能够使用以下方法成功地对个人推文进行分类:

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)