Stop words

Python 情感分析

Violeta Misheva

Data Scientist

什麼是 stop words?如何找出?

Stop words:出現過於頻繁且資訊量低的詞

  • 多數語言都有 stop words 清單

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

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

用文字雲看 stop words

  • 未移除 stop words 的文字雲 未移除 stop words 的文字雲
  • 已移除 stop words 的文字雲 已移除 stop words 的文字雲
Python 情感分析

從文字雲移除 stop words

# 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 與 stop words

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...