시작하기무료로 시작하기

연관과 비연관 계산하기

도서관이 다시 문의해 왔어요. Twilight으로 Harry Potter를 홍보하자는 추천에 대해, 두 도서가 서로 비연관(dissociation)일 수 있어 홍보에 부정적 영향을 줄까 걱정하고 있어요. 이에 해당하지 않는지 확인해 달라고 요청했어요.

여러분은 곧바로 연관과 비연관을 연속적으로 측정하는 Zhang 지표를 떠올렸어요. 연관은 양수, 비연관은 음수로 나타나요. 앞선 연습과 마찬가지로 DataFrame books와 별칭 np로 불러온 numpy가 제공되어 있어요. Zhang 지표는 다음과 같이 계산해요:

$$Zhang(A \rightarrow B) = $$ $$\frac{Support(A \& B) - Support(A) Support(B)}{ max[Support(AB) (1-Support(A)), Support(A)(Support(B)-Support(AB))]}$$

이 연습은 강의의 일부입니다

Python으로 배우는 Market Basket Analysis

강의 보기

연습 안내

  • {Twilight}의 지지도와 {Potter}의 지지도를 계산하세요.
  • {Twilight, Potter}의 지지도를 계산하세요.
  • 분모 식을 완성하세요.
  • {Twilight} \(\rightarrow\) {Potter}에 대한 Zhang 지표를 계산하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# Compute the support of Twilight and Harry Potter
supportT = books['Twilight'].____
supportP = books['Potter'].____

# Compute the support of both books
supportTP = ____.mean()

# Complete the expressions for the numerator and denominator
numerator = supportTP - supportT*supportP
denominator = ___(supportTP*(1-supportT), supportT*(supportP-supportTP))

# Compute and print Zhang's metric
zhang = ____ / ____
print(zhang)
코드 편집 및 실행