트윗에 대한 분류자를 훈련시키고 있습니다. 그러나 분류기의 정확도는 100 %이며 가장 유익한 기능 목록에는 아무 것도 표시되지 않는다는 것이 문제입니다. 아무도 내가 뭘 잘못하고 있는지 알아? 나는 분류 자에 대한 나의 모든 입력이 정확하다고 믿습니다. 그래서 그것이 잘못 될지 전혀 모르겠습니다.NLTK Naive Bayes 분류 자 훈련 문제
feature_set = [(find_features (all_words :
import nltk
import random
file = open('Train/train.txt', 'r')
documents = []
all_words = [] #TODO remove punctuation?
INPUT_TWEETS = 3000
print("Preprocessing...")
for line in (file):
# Tokenize Tweet content
tweet_words = nltk.word_tokenize(line[2:])
sentiment = ""
if line[0] == 0:
sentiment = "negative"
else:
sentiment = "positive"
documents.append((tweet_words, sentiment))
for word in tweet_words:
all_words.append(word.lower())
INPUT_TWEETS = INPUT_TWEETS - 1
if INPUT_TWEETS == 0:
break
random.shuffle(documents)
all_words = nltk.FreqDist(all_words)
word_features = list(all_words.keys())[:3000] #top 3000 words
def find_features(document):
words = set(document)
features = {}
for w in word_features:
features[w] = (w in words)
return features
#Categorize as positive or Negative
feature_set = [(find_features(all_words), sentiment) for (all_words, sentment) in documents]
training_set = feature_set[:1000]
testing_set = feature_set[1000:]
print("Training...")
classifier = nltk.NaiveBayesClassifier.train(training_set)
print("Naive Bayes Accuracy:", (nltk.classify.accuracy(classifier,testing_set))*100)
classifier.show_most_informative_features(15)
문제 같은데 [0]'은'int''0'으로 라인 '에있는 문자를 비교입니다. 귀하의 의견이 실제로 부정적인 정서를 나타 내기 위해 null 바이트를 사용하는지 의심 스럽습니다. – alexis