开始使用免费开始使用

比较 linear_kernel 与 cosine_similarity

在本练习中,您已获得包含 1,000 篇文档 tf-idf 向量的 tfidf_matrix。您的任务是先使用 cosine_similarity,然后使用 linear_kernel,为这些向量生成余弦相似度矩阵。

随后我们将比较这两个函数的计算时间。

本练习是课程的一部分

Python 中的 NLP 特征工程

查看课程

交互式实操练习

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

# Record start time
start = time.time()

# Compute cosine similarity matrix
cosine_sim = ____(____, ____)

# Print cosine similarity matrix
print(cosine_sim)

# Print time taken
print("Time taken: %s seconds" %(time.time() - start))
编辑并运行代码