상품 리뷰의 빈도 분석
이제 더 큰 TechZone 상품 리뷰 데이터셋을 사용할 수 있어요. 이전과 마찬가지로 리뷰를 전처리하고 BoW 표현 X로 변환해 두었습니다. 이번 과제는 단어 빈도를 분석해 데이터셋에서 가장 흔한 용어들을 찾아내는 것입니다.
분석에 도움이 되도록 get_top_ten()이라는 보조 함수가 제공됩니다. 이 함수는 단어 목록과 해당 빈도를 입력으로 받아, 가장 자주 등장하는 10개 단어와 그 빈도를 반환합니다.
이 연습은 강의의 일부입니다
Python으로 배우는 Natural Language Processing (NLP)
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
def preprocess(text):
text = text.lower()
tokens = word_tokenize(text)
tokens = [word for word in tokens if word not in string.punctuation]
return " ".join(tokens)
cleaned_reviews = [preprocess(review) for review in product_reviews]
X = vectorizer.fit_transform(cleaned_reviews)
# Get word counts
word_counts = np.____(X.____, axis=0)
# Get words
words = vectorizer.____
top_words_with_stopwords, top_counts_with_stopwords = get_top_ten(words, word_counts)
print(top_words_with_stopwords, top_counts_with_stopwords)