私はこの分類子に取り組んできました。唯一の問題は、テストセットです。Python NLTKの書式設定テストセット
train = pd.read_csv(os.path.join(os.path.dirname(__file__), 'data', 'labeledTrainData.tsv'), header=0, \
delimiter="\t", quoting=3)
test = pd.read_csv(os.path.join(os.path.dirname(__file__), 'data', 'testData.tsv'), header=0, delimiter="\t", \
quoting=3)
documents = []
for review in train.values:
sentiment = 'pos' if review[1] == 1 else 'neg'
split = review[2].split(), sentiment
for word in split[0]:
word = re.sub(r'[^\w\s]', '', word)
documents.append(split)
word_features = nltk.FreqDist(chain(*[i for i, j in documents]))
word_features = list(word_features.keys())[:100]
train_set = [({i: (i in tokens) for i in word_features}, tag) for tokens, tag in documents[:1000]]
classifier = nltk.NaiveBayesClassifier
classifier.train(train_set)
print(nltk.classify.accuracy(classifier, test))
classifier.show_most_informative_features(5)
この例では、90/10のように使用され、分割されて使用されているセットがあります。ここでは、実際には2つの異なるデータセット(1つのラベル、1つのテスト)があります。
train_set(下図短縮バージョン)が単語がword_keysにある場合、レビューが正または負である場合に言ってブール値を持つタプルのリストである:
[({'beautician,': False, 'hubris,': False, '/>BTW:': False, 'nondenominational': False, 'diapered,': False, 'matter).': False, 'fascist\\"': False, 'Russian,gay': False, '/>\\"Ladies': False, 'purport': False, 'locker-room': False, 'Enjoy"': False, 'exposition': False, 'decisions\\"': False, 'N(n***as)': False, 'Duhllywood),': False, 'cataclysmic': False, 'reviews,': False, 'marry;': False, 'Gordon),': False, 'now-nostalgic': False, 'avoid!!!!"': False, 'coin;': False, 'infiltrators': False, 'smalltime': False, "`knows'": False, 'callous': False, 'actors...it': False, 'Fox,': False, "'78": False, 'Givney': False, 'cinematography):': False, 'misconstrued,': False, 'bathing;': False, 'Hepburn,': False, 'noise,': False, 'BG´s.': False, 'ship.In': False, "'60s.)<br": False, 'Odder': False, 'holes,disgustingly': False, '/>contact': False, 'Croasdell': False, 'trips\\"': False, 'acting.Yet': False, 'firearm.': False, 'businesspeople': False, 'Tomilinson': False, 'ways...<br': False, 'cast...ouch.': False, "Alexandra's": False, "lost.'": False, 'anwers,': False, 'dissertation': False, 'Perry': False, 'phenom': False, '\\"Cleopatra\\",': False, '"Revolt': False, 'secured': False, "romance',": False, 'retentively': False, '/>1/2': False, 'photography/\\"You': False, 'did--': False, 'consulate': False, 'ocurred.': False, 'profession': False, 'insane.': False, 'hysterics)': False, 'UPN.<br': False, 'effects--after': False, 'IMAGE,': False, 'recognizable.<br': False, "Kinky'with": False, 'death\x97it': False, 'Wizard\\"': False, 'pemberton,': False, 'Belting': False, 'boast.': False, 'Schlock!!': False, 'filmed)': False, 'overplotted': False, 'wiring,': False, 'comedy)': False, '`SS': False, 'foibles.': False, 'Germna': False, 'Waverly': False, 'Oxford-educated': False, 'reviews.Anyway': False, 'SANE': False, 'expressively': False, 'cr*p.': False, 'ex-priest': False, 'ITC': False, '/>Sara': False, 'exoticism-oriented': False, "'hello'": False, '"......in': False, 'hesitates': False}, 'neg')]
テストセットがまだある間この:私は行くだろうどのように
id review
0 "12311_10" "Naturally in a film who's main themes are of ...
1 "8348_2" "This movie is a disaster within a disaster fi...
2 "5828_4" "All in all, this is a movie for kids. We saw ...
3 "7186_2" "Afraid of the Dark left me with the impressio...
4 "12128_7" "A very accurate depiction of small time mob l...
... ... ...
24997 "2531_1" "I was so disappointed in this movie. I am ver...
24998 "7772_8" "From the opening sequence, filled with black ...
24999 "11465_10" "This is a great horror film for people who do...
[25000 rows x 2 columns]
今ofcourseの私は、私は単純に、このデータセットに訓練することができない問題、元はちょうど上記test_setのように見えたの取得のみ値1を含むこの感情があったか0これを訓練することについてそれに対してテストセットを使用していますか?私はいくつかの例があることを知っているが、それは私がやっているのとまったく同じではない。
ええ、私はおそらく何かを逃しましたか?私は使用する3つのファイルを持っています。これは、ラベル付きトレーニングセット、未学習トレーニングセット、およびテストセットです。私はラベル付きセットで訓練したことを理解していましたが、ラベルが付いていないセット(この場合はテストセット)を置くことがポイントだと思っていました。ラベルのないセットはどこに入っていますか?最終的に私は自分のレビューでテストしたいと思っていますが、これはラベルが付けられず、この訓練されたセットに従ってレビューにラベルを付けます。途中で答えをありがとう、それをありがとう! @alexis – dnsko
分類されていない入力に対して分類器を使用できます。それが何のためだ。しかし、割り当てられたラベルが正しいかどうかを判断する方法はありません。 – alexis