플그래밍/파이써언

[파이썬] 노이즈 및 불용어, 이것만은 알고 가자 (nltk)

훗티v 2023. 6. 25. 04:42
728x90
반응형

텍스트 마이닝에서 불필요하거나 분석 대상이 아닌 단어를 뜻하는 노이즈 및 불용어 제거는 필수 전처리 단계이며 분석결과의 정확성에 크게 영향을 끼친다.

 

nltk에서는 기본적으로 아래와 같은 불용어 리스트를 제공한다.

 

['i', 'me', 'my', 'myself', 'we', 'our', 'ours', 'ourselves', 'you', "you're", "you've", "you'll", "you'd", 'your', 'yours', 'yourself', 'yourselves', 'he', 'him', 'his', 'himself', 'she', "she's", 'her', 'hers', 'herself', 'it', "it's", 'its', 'itself', 'they', 'them', 'their', 'theirs', 'themselves', 'what', 'which', 'who', 'whom', 'this', 'that', "that'll", 'these', 'those', 'am', 'is', 'are', 'was', 'were', 'be', 'been', 'being', 'have', 'has', 'had', 'having', 'do', 'does', 'did', 'doing', 'a', 'an', 'the', 'and', 'but', 'if', 'or', 'because', 'as', 'until', 'while', 'of', 'at', 'by', 'for', 'with', 'about', 'against', 'between', 'into', 'through', 'during', 'before', 'after', 'above', 'below', 'to', 'from', 'up', 'down', 'in', 'out', 'on', 'off', 'over', 'under', 'again', 'further', 'then', 'once', 'here', 'there', 'when', 'where', 'why', 'how', 'all', 'any', 'both', 'each', 'few', 'more', 'most', 'other', 'some', 'such', 'no', 'nor', 'not', 'only', 'own', 'same', 'so', 'than', 'too', 'very', 's', 't', 'can', 'will', 'just', 'don', "don't", 'should', "should've", 'now', 'd', 'll', 'm', 'o', 're', 've', 'y', 'ain', 'aren', "aren't", 'couldn', "couldn't", 'didn', "didn't", 'doesn', "doesn't", 'hadn', "hadn't", 'hasn', "hasn't", 'haven', "haven't", 'isn', "isn't", 'ma', 'mightn', "mightn't", 'mustn', "mustn't", 'needn', "needn't", 'shan', "shan't", 'shouldn', "shouldn't", 'wasn', "wasn't", 'weren', "weren't", 'won', "won't", 'wouldn', "wouldn't"]

 

regex를 활용한 RegexpTokenizer로 단어 토큰화를 거쳐 불용어를 제거하기 전과 후의 결과입니다.

 

from nltk import RegexpTokenizer
from nltk.corpus import stopwords

stopwords_eng = set(stopwords.words('english'))

text = "I went to the store yesterday and bought some bread and milk, but I realized I forgot my wallet at home."

tokenize = RegexpTokenizer("[\w']+").tokenize(text.lower())

result = [i for i in tokenize if i not in stopwords_eng]

for each in tokenize:
    print(each)

 

i, to, the 등과 같은 불용어가 제거된 결과물

 

 

 

 

 

쿠팡 광고 클릭 시, 이에 따른 일정액의 수수료를 제공받으며 블로그 운영에 큰 도움이 됩니다. 감사합니다.

반응형