开始使用免费开始使用

用 conviction 推广电子书

在上一个练习中,我们定义了一个用于计算 conviction 的函数。我们被要求将该函数应用到 goodreads-10k 数据集中的所有两本书的排列组合上。本练习中,我们将把它应用到之前用过的三本最受欢迎的书上,来测试这个函数:The Hunger GamesHarry PotterTwilight

函数已为您定义,可通过 conviction 使用。回忆一下,它接收前件和后件两个参数。此外,前面练习中的 books DataFrame 的各列已提供为 3 个独立的 DataFrame:pottertwilighthunger

本练习是课程的一部分

Python 中的购物篮分析

查看课程

练习说明

  • 计算 {Twilight} \(\rightarrow\) {Potter}{Potter} \(\rightarrow\) {Twilight} 的 conviction。
  • 计算 {Twilight} \(\rightarrow\) {Hunger}{Hunger} \(\rightarrow\) {Twilight} 的 conviction。
  • 计算 {Potter} \(\rightarrow\) {Hunger}{Hunger} \(\rightarrow\) {Potter} 的 conviction。

交互式实操练习

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

# Compute conviction for twilight -> potter and potter -> twilight
convictionTP = conviction(twilight, potter)
convictionPT = conviction(____, twilight)

# Compute conviction for twilight -> hunger and hunger -> twilight
convictionTH = conviction(____, ____)
convictionHT = ____(hunger, twilight)

# Compute conviction for potter -> hunger and hunger -> potter
convictionPH = ____(potter, hunger)
convictionHP = ____

# Print results
print('Harry Potter -> Twilight: ', convictionHT)
print('Twilight -> Potter: ', convictionTP)
编辑并运行代码