2012-01-11 3 views
6

저는 NTLK/Python 초보자이며 CategorizedPlaintextCorpusReader를 사용하여 내 코퍼스를로드 할 수 있었지만 실제로 텍스트를 분류하고 데이터를 사용하는 방법은 무엇입니까?Python NLTK의 카테고리 분류에 내 자신의 코퍼스 사용

>>> from nltk.corpus.reader import CategorizedPlaintextCorpusReader 
>>> reader = CategorizedPlaintextCorpusReader('/ebs/category', r'.*\.txt', cat_pattern=r'(.*)\.txt') 
>>> len(reader.categories()) 
234 
+0

볼 (그러나 노트.. 당신의 cap_pattern에서, 그 당신이 원하는 정말 무엇인지 확인하시기 바랍니다 당신은 샘플 모음에있는 파일 당 하나의 카테고리를 보인다) http://stackoverflow.com/questions/29275614/using-my-own-corpus- 대신 영화 리뷰 - corpus-for-classification-in-nltk – alvas

답변

6

당신이 단어의 가방 순진 베이 즈 분류기를 원하는 가정 기능 :

from nltk import FreqDist 
from nltk.classify.naivebayes import NaiveBayesClassifier 

def make_training_data(rdr): 
    for c in rdr.categories(): 
     for f in rdr.fileids(c): 
      yield FreqDist(rdr.words(fileids=[f])), c 

clf = NaiveBayesClassifier.train(list(make_training_data(reader))) 

결과 clfclassify 방법

단어의 FreqDist 사용할 수 있습니다.

: