开始使用免费开始使用

UFO 数据集建模(第 2 部分)

最后,您将使用我们创建的文本向量 desc_tfidf 来构建模型,并使用 filtered_words 列表创建一个经过筛选的文本向量。看看是否能根据文本来预测目击事件的 type。本题将使用朴素贝叶斯模型。

本练习是课程的一部分

Python 中的机器学习预处理

查看课程

练习说明

  • 通过在索引中传入 filtered_words 的列表来筛选 desc_tfidf 向量。
  • filtered_text 特征与 y 进行划分,确保训练集和测试集中的类别分布相同;使用 random_state42
  • 使用 nb 模型的 .fit() 拟合 X_trainy_train
  • 打印 nb 模型在 X_testy_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
____
编辑并运行代码