开始使用免费开始使用

TED 演讲推荐器

在本练习中,您将基于 TED 演讲的逐字稿构建一个推荐系统。已为您提供 get_recommendations() 函数,它接收演讲标题、相似度矩阵以及 indices 序列作为参数,并输出最相似演讲的列表。indices 已经提供。

同时,您还获得了包含约 500 个 TED 演讲逐字稿的 transcripts 序列。您的任务是为这些逐字稿的 tf-idf 向量生成一个余弦相似度矩阵。

最后,我们将为巴西企业家 Bel Pesce 的演讲"5 ways to kill your dreams"生成推荐。

本练习是课程的一部分

Python 中的 NLP 特征工程

查看课程

练习说明

  • 使用英文停用词初始化一个 TfidfVectorizer,命名为 tfidf
  • 拟合并转换 transcripts 构造 tfidf_matrix
  • 使用 tfidf_matrix 生成余弦相似度矩阵 cosine_sim
  • 使用 get_recommendations() 为"5 ways to kill your dreams"生成推荐。

交互式实操练习

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

# Initialize the TfidfVectorizer 
tfidf = ____

# Construct the TF-IDF matrix
tfidf_matrix = ____

# Generate the cosine similarity matrix
cosine_sim = ____
 
# Generate recommendations 
print(get_recommendations(____, ____, indices))
编辑并运行代码