停用词

Python 中的情感分析

Violeta Misheva

Data Scientist

什么是停用词,如何找到?

停用词:出现过于频繁、信息量低的词

  • 大多数语言都有停用词表

      {'the', 'a', 'an', 'and', 'but', 'for', 'on', 'in', 'at' ...}
    
  • 语境很重要

      {'movie', 'movies', 'film', 'films', 'cinema'}
    
Python 中的情感分析

结合词云看停用词

  • 未去除停用词的词云 未去除停用词的词云
  • 去除停用词后的词云 去除停用词后的词云
Python 中的情感分析

从词云中移除停用词

# Import libraries
from wordcloud import WordCloud, STOPWORDS
import matplotlib.pyplot as plt
# Define the stopwords list
my_stopwords = set(STOPWORDS)
my_stopwords.update(["movie", "movies", "film", "films", "watch", "br"])
# Generate and show the word cloud
my_cloud = WordCloud(background_color='white', stopwords=my_stopwords).generate(name_string)
plt.imshow(my_cloud, interpolation='bilinear')
Python 中的情感分析

BOW 中的停用词

from sklearn.feature_extraction.text import CountVectorizer, ENGLISH_STOP_WORDS
# Define the set of stop words
my_stop_words = ENGLISH_STOP_WORDS.union(['film', 'movie', 'cinema', 'theatre'])
vect = CountVectorizer(stop_words=my_stop_words) 
vect.fit(movies.review)
X = vect.transform(movies.review)
Python 中的情感分析

让我们练习!

Python 中的情感分析

Preparing Video For Download...