Я пытаюсь создать свой собственный корпус для анализа настроений твитов (будь то положительные или отрицательные).Классификация с использованием NLTK corpus обзоров фильмов
Я сначала пытаюсь использовать существующий корпус для просмотра фильмов NLTK. Однако, если я использую этот код:
import string
from itertools import chain
from nltk.corpus import movie_reviews as mr
from nltk.corpus import stopwords
from nltk.probability import FreqDist
from nltk.classify import NaiveBayesClassifier as nbc
import nltk
stop = stopwords.words('english')
documents = [([w for w in mr.words(i) if w.lower() not in stop and w.lower() not in string.punctuation], i.split('/')[0]) for i in mr.fileids()]
word_features = FreqDist(chain(*[i for i,j in documents]))
word_features = word_features.keys()[:100]
numtrain = int(len(documents) * 90/100)
train_set = [({i:(i in tokens) for i in word_features}, tag) for tokens,tag in documents[:numtrain]]
test_set = [({i:(i in tokens) for i in word_features}, tag) for tokens,tag in documents[numtrain:]]
classifier = nbc.train(train_set)
print nltk.classify.accuracy(classifier, test_set)
classifier.show_most_informative_features(5)
Im получая на выходе:
0.31
Most Informative Features
uplifting = True pos : neg = 5.9 : 1.0
wednesday = True pos : neg = 3.7 : 1.0
controversy = True pos : neg = 3.4 : 1.0
shocks = True pos : neg = 3.0 : 1.0
catchy = True pos : neg = 2.6 : 1.0
Вместо ожидаемого результата (см Classification using movie review corpus in NLTK/Python):
0.655
Most Informative Features
bad = True neg : pos = 2.0 : 1.0
script = True neg : pos = 1.5 : 1.0
world = True pos : neg = 1.5 : 1.0
nothing = True neg : pos = 1.5 : 1.0
bad = False pos : neg = 1.5 : 1.0
Я использую точно такой же код, как и на другой странице StackOverflow, мой NLTK (и их) обновлен, и у меня также есть последний корпус для просмотра фильмов. Кто-нибудь с идеей, что происходит не так?
Спасибо!
лучше, как только вы видите, что длина вашего корпуса. –