1

Python で TextBlob を使用して、ツイートに Naive Bayes 分類子を実装しようとしています。データセットをトレーニングすることができ、以下を使用して個々のツイートを正常に分類できます。

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' がありません

4

1 に答える 1

0

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)
于 2016-07-17T17:57:14.543 に答える