我試圖用一個nltk樸素分類器來分類電影的流派。但是我得到了一些奇怪的結果。目前它只根據輸入的流派數量進行猜測。NLTK樸素貝葉斯分類器奇怪的結果
如果我輸入兩個動作電影,並且每個猜測都會有一個喜劇動作。當然,我希望它基於輸入的文本:
def RemoveStopWords(wordText):
keep_list = []
for word in wordText:
if word not in wordStop:
keep_list.append(word.lower())
return set(keep_list)
def getFeatures(element):
splitter=re.compile('\\W*')
f = {}
plot = [s for s in RemoveStopWords(splitter.split(element['imdb']['plot']))
if len(s)>5 and len(s) < 15]
for w in plot:
f[w]= w
return f
def FindFeaturesForList(MovieList):
featureSet = []
for w in MovieList:
print w['imdb']['title']
try:
for genre in w['imdb']['genres']:
featureSet.append((getFeatures(w), genre))
except:
print "Error when retriving genre, skipping element"
return featureSet
featureList = FindFeaturesForList(trainset)
cl = nltk.NaiveBayesClassifier.train(featureList)
所以每當我做一個cl.classify(電影),它返回的最常見的輸入風格,我究竟做錯了什麼?
使用兩個喜劇和一個動作片似乎太小的訓練集。你有沒有試過用至少*幾百部電影訓練分類器? – unutbu 2013-05-10 19:59:28
是的,我已經嘗試過數百次,但是在查看數據時,猜測是基於流派的數量而不是輸入的文本。 – TheTango 2013-05-10 21:00:53
你可以發佈'cl.show_most_informative_features(5)'嗎? – unutbu 2013-05-10 21:05:50