开始使用免费开始使用

文本向量化

现在请将 UFO 数据集中的 desc 列转换为 tf/idf 向量,因为这个字段很可能包含有用的信息。

本练习是课程的一部分

Python 中的机器学习预处理

查看课程

练习说明

  • 打印 desc 列的 .head()
  • 实例化一个 TfidfVectorizer() 对象。
  • 使用 vec 拟合并转换 desc 列。
  • 打印 desc_tfidf 向量的 .shape,查看由此产生的列数。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Take a look at the head of the desc field
print(____)

# Instantiate the tfidf vectorizer object
vec = ____

# Fit and transform desc using vec
desc_tfidf = vec.____

# Look at the number of columns and rows
print(____.shape)
编辑并运行代码