用置信度细化支持度
在上一练习汇报了您的发现后,图书馆向您追问关联的方向性:他们应该用《Harry Potter》来推广《Twilight》,还是用《Twilight》来推广《Harry Potter》?
考虑之后,您决定计算具有方向性的评价指标——置信度(confidence),不同于支持度。您将分别计算 {Potter} \(\rightarrow\) {Twilight} 和 {Twilight} \(\rightarrow\) {Potter} 的置信度。已为您导入 DataFrame books,其中每本书各一列:Potter 和 Twilight。
本练习是课程的一部分
Python 中的购物篮分析
练习说明
- 计算 {Potter, Twilight} 的支持度。
- 计算 {Potter} 的支持度。
- 计算 {Twilight} 的支持度。
- 分别计算 {Potter} \(\rightarrow\) {Twilight} 和 {Twilight} \(\rightarrow\) {Potter} 的置信度。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Compute support for Potter and Twilight
supportPT = np.logical_and(____, ____).mean()
# Compute support for Potter
supportP = books['Potter'].____
# Compute support for Twilight
supportT = ____
# Compute confidence for both rules
confidencePT = supportPT / ____
confidenceTP = ____ / supportT
# Print results
print('{0:.2f}, {1:.2f}'.format(confidencePT, confidenceTP))