至於我可以使用NLTK分類理解的例子:如何NLTK分類使用元數據
- http://nbviewer.ipython.org/github/carljv/Will_it_Python/blob/master/MLFH/CH3/ch3_nltk.ipynb
- http://www.nltk.org/book/ch06.html
- NLTK classify interface using trained classifier
- Implementing Bag-of-Words Naive-Bayes classifier in NLTK
- http://my.safaribooksonline.com/book/databases/9781783280995/11dot-sentiment-analysis-of-twitter-data/id286781656#X2ludGVybmFsX0h0bWxWaWV3P3htbGlkPTk3ODE3ODMyODA5OTUlMkZpZDI4Njc4MjEwNCZxdWVyeT0=
他們似乎只處理句子本身的功能。所以,你必須......
corpus =
[
("This is a sentence"),
("This is another sentence")
]
...和你申請的一些功能,如count_words_ending_in_a_vowel()來了句本身。
相反,我想一塊之外的數據應用到句子,不是從文本本身產生的,但外部的標籤,如:
corpus =
[
("This is a sentence", "awesome"),
("This is another sentence", "not awesome")
]
或者
corpus =
[
{"text": "This is a sentence", "label": "awesome"},
{"text": "This is another sentence", "label": "not awesome"}
]
(如果我可能有多個外部標籤)
我的問題是:鑑於我的數據集中包含這些外部標籤,如何將語料庫重新格式化爲格式NaiveBayesClassifier.train()
預計?我知道我也需要在上面的「text」字段上應用tokenizer,但是我應該輸入到NaiveBayesClassifier.train函數中的總格式是什麼?
申請
classifier = nltk.NaiveBayesClassifier.train(goods)
print(classifier.show_most_informative_features(32))
我的更廣泛的目標---我想在看詞頻如何鑑別是能夠預測的標籤,這套的話是最翔實從分離標籤彼此。這種類型具有k-means的感覺,但我被告知我應該能夠在NLTK中完全做到這一點,並且只是在將其表達爲適當的數據輸入格式時遇到了麻煩。
嗯,我的數據是在你所描述的格式,我的分類保存返回'>>>打印classifier.show_most_informative_features(4) 大多數信息量大的特點 無 '。我認爲這意味着我有一個語法錯誤。但它似乎意味着我的數據/模型有問題? – Mittenchops