结合停用词的航空公司情感分析
给您一个名为 tweets 的数据集,包含顾客对航空公司的评价及其情感标签。它由两列组成:airline_sentiment 和 text。其中情感可以是 positive、negative 或 neutral,text 是推文的文本内容。
在本练习中,您将创建一个 BOW(词袋)表示,并考虑停用词的处理。请记住,停用词通常信息量不高,您可能希望将其移除。这样可以使词汇表更小,最终特征也会更少。请注意,我们可以在默认停用词列表的基础上,加入与当前语境相关的词来进行扩充。
本练习是课程的一部分
Python 中的情感分析
练习说明
- 导入英语默认停用词列表。
- 使用给定列表
['airline', 'airlines', '@']扩充默认停用词,创建my_stop_words。 - 在向量化器中指定 stop_words 参数。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import the stop words
from sklearn.feature_extraction.text import CountVectorizer, ____
# Define the stop words
my_stop_words = ____.____(['airline', 'airlines', '@'])
# Build and fit the vectorizer
vect = CountVectorizer(____=my_stop_words)
vect.fit(tweets.text)
# Create the bow representation
X_review = vect.transform(tweets.text)
# Create the data frame
X_df = pd.DataFrame(X_review.toarray(), columns=vect.get_feature_names())
print(X_df.head())