0

私は別の学習方法(Decision Tree、NaiveBayes、Maxent)を使用しています。その相対的なパフォーマンスを比較して、それらの最良の方法を知ることができますか? 精度を得るために決定ツリーを実装する方法は?デシジョンツリーnltk

import string 
from sklearn.tree import DecisionTreeClassifier 
from sklearn.metrics import confusion_matrix 
import nltk, nltk.classify.util, nltk.metrics 
from nltk.classify import MaxentClassifier 
from nltk.collocations import BigramCollocationFinder 
from nltk.metrics import BigramAssocMeasures 
from nltk.probability import FreqDist, ConditionalFreqDist 
from sklearn import cross_validation 
import nltk.classify.util 
from nltk.classify import NaiveBayesClassifier 
from nltk.corpus import movie_reviews 

from nltk.classify import MaxentClassifier 
from nltk.corpus import movie_reviews 
from nltk.corpus import movie_reviews as mr 

stop = stopwords.words('english') 
words = [([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()] 

def word_feats(words): 
return dict([(word, True) for word in words]) 

negids = movie_reviews.fileids('neg') 
posids = movie_reviews.fileids('pos') 

negfeats = [(word_feats(movie_reviews.words(fileids=[f])), 'neg') for f in negids] 
posfeats = [(word_feats(movie_reviews.words(fileids=[f])), 'pos') for f in posids] 

negcutoff = len(negfeats)*3/4 
poscutoff = len(posfeats)*3/4 

trainfeats = negfeats[:negcutoff] + posfeats[:poscutoff] 
DecisionTree_classifier = DecisionTreeClassifier.train(trainfeats, binary=True, depth_cutoff=20, support_cutoff=20, entropy_cutoff=0.01) 
print(accuracy(DecisionTree_classifier, testfeats)) 
+0

ステートメントの最後に余分な閉じ括弧があります。 – blacksite

答えて

0

このコードでは、精度を印刷しているので、実際の質問は何ですか?

+0

これは答えではありません。質問を回答として投稿しないようにしてください。コメントを投稿するのに十分な担当者がいない場合は、実行するまでお待ちください –

0

nltk3のコード(またはドキュメント文字列)を調べる必要があります。また、nltkの本に書かれている例は何の変更もなしに動作します。

http://www.nltk.org/book/ch06.html#DecisionTreesを参照するか、またはあなただけの試験サンプルを実行することができますし、あなたの精度であること偽陽性と偽陰性率を自分

を数えます。