Python 中的购物篮分析
Isaiah Hull
Visiting Associate Professor of Finance, BI Norwegian Business School
$$Support(X) = \frac{Frequency(X)}{N}$$
$$Support(X \rightarrow Y) = \frac{Frequency(X \& Y)}{N}$$
$$Confidence(X \rightarrow Y) = \frac{Support(X \rightarrow Y)} {Support(X)}$$
$$Lift(X \rightarrow Y) = \frac{Support(X \rightarrow Y)}{Support(X) Support(Y)}$$
$$Leverage(X \rightarrow Y) = $$ $$Support(X \& Y) - Support(X) Support(Y)$$
# 计算《暮光之城》和《哈利·波特》的支持度
supportTP = np.logical_and(books['Twilight'], books['Potter']).mean()
# 计算《暮光之城》的支持度
supportT = books['Twilight'].mean()
# 计算《哈利·波特》的支持度
supportP = books['Potter'].mean()
# 计算并打印杠杆率
leverage = supportTP - supportP * supportT
print(leverage)
0.018
$$Conviction(X \rightarrow Y) = $$ $$\frac{Support(X) Support(\bar{Y})} {Support(X \& \bar{{Y}})}$$




# 计算《暮光之城》和《哈利·波特》的支持度 supportTP = np.logical_and(books['Twilight'], books['Potter']).mean() # 计算《暮光之城》的支持度 supportT = books['Twilight'].mean()# 计算"非《哈利·波特》"的支持度 supportnP = 1.0 - books['Potter'].mean()# 计算《暮光之城》且非《哈利·波特》的支持度 supportTnP = supportT - supportPT# 计算确信度 conviction = supportT*supportnP / supportTnP print(conviction)1.16
Python 中的购物篮分析