从客户评论构建词汇表
您是 TechZone(消费电子公司)产品分析团队的一员。您收到了一小批关于一款新设备的客户评论。为分析这些评论,您将先对文本进行预处理,并构建词汇表——这是由唯一词组成的列表,用于定义将每条评论表示为数值数据时所用的特征。
我们已为您预加载了 preprocess() 函数。它会将文本转为小写、进行分词,并去除标点符号。
本练习是课程的一部分
Python 中的自然语言处理(NLP)
练习说明
- 使用
preprocess()函数预处理数据集中每条评论。 - 在预处理后的评论上拟合
vectorizer。 - 打印得到的词汇表。
交互式实操练习
通过完成这段示例代码来试试这个练习。
reviews = [
"The product is fantastic! It works like a charm.",
"I hated the product. It broke after one use.",
"Product was okay, not the best, but fine overall."
]
# Preprocess the reviews
cleaned_reviews = [____ for ____ in ____]
vectorizer = CountVectorizer()
# Fit the vectorizer
vectorizer.____
# Print the vocabulary
print(vectorizer.____)