开始使用免费开始使用

阈值(cutoff point)

在本练习以及本章余下内容中,您将使用包含多家餐厅数据的 restaurants DataFrame。您的最终目标是构建一个餐厅推荐引擎,但首先需要清理数据。

这个版本的 restaurants 来自多个来源,其中 cuisine_type 列充满了拼写错误,按理只应包含 italianamericanasian 这 3 种菜系类型。类别太多,手动重映射不可扩展,因此更适合使用字符串相似度。

在此之前,您需要用 thefuzzprocess.extract() 函数,为每个类别找到最"远"的拼写错误对应的相似度分数,从而确定相似度的阈值。

本练习是课程的一部分

Python 数据清洗

查看课程

交互式实操练习

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

# Import process from thefuzz
____

# Store the unique values of cuisine_type in unique_types
unique_types = ____

# Calculate similarity of 'asian' to all values of unique_types
print(process.____('____', ____, limit = len(____)))

# Calculate similarity of 'american' to all values of unique_types
print(____('____', ____, ____))

# Calculate similarity of 'italian' to all values of unique_types
print(____)
编辑并运行代码