例えば、CSVの内容は次のようである場合:
CSV
Size,Color,Shape,Accept
small,blue,oval,yes
small,green,oval,yes
big,green,oval,no
big,red,square,no
small,red,square,no
small,blue,square,yes
big,red,circle,yes
そして、私たちは-小さな赤い楕円項目があるかどうかを知りたいですnltk Naive Bayesを使用して承認された場合、次のコードを使用できます。
python
import csv
import nltk
f = open('C:/Users/Amrit/Documents/Data/exp.csv')
csv_f = csv.reader(f)
csv_f.next() #skip the header line
dataset = []
for row in csv_f:
dataset.append(({'size': row[0], 'color': row[1], 'shape': row[2]}, row[3]))
print (dataset)
classifier = nltk.NaiveBayesClassifier.train(dataset)
mydata = {'size':'small', 'color':'red', 'shape':'oval'}
print (mydata, classifier.classify(mydata))
注:私も学んでいます。 @Franscisco Couzoと@Milad Mが提供するリンクありがとう
あなたは[this](http://www.nltk.org/book/ch06.html)を読んでいますか? 'NaiveBayesClassifier'の使い方の例があります –
あなたの答えはここにあります:[link](http://stackoverflow.com/questions/20827741/nltk-naivebayesclassifier-training-for-sentiment-analysis) –