UFO 数据集建模(第 2 部分)
最后,您将使用我们创建的文本向量 desc_tfidf 来构建模型,并使用 filtered_words 列表创建一个经过筛选的文本向量。看看是否能根据文本来预测目击事件的 type。本题将使用朴素贝叶斯模型。
本练习是课程的一部分
Python 中的机器学习预处理
练习说明
- 通过在索引中传入
filtered_words的列表来筛选desc_tfidf向量。 - 将
filtered_text特征与y进行划分,确保训练集和测试集中的类别分布相同;使用random_state为42。 - 使用
nb模型的.fit()拟合X_train和y_train。 - 打印
nb模型在X_test和y_test上的.score()。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Use the list of filtered words we created to filter the text vector
filtered_text = ____[:, list(____)]
# Split the X and y sets using train_test_split, setting stratify=y
X_train, X_test, y_train, y_test = ____(____.toarray(), ____, ____, random_state=42)
# Fit nb to the training sets
____
# Print the score of nb on the test sets
____