교차 판매 제품 선정
작은 식료품점이 껌을 커피, 시리얼, 또는 빵과 함께 교차 판매하기로 했어요. 세 가지 중 어떤 품목이 가장 적합한지 판단하기 위해 점주가 실험을 진행했습니다. 일주일 동안 계산대 옆에서 껌을 판매하고, 껌이 커피, 시리얼, 또는 빵과 함께 구매된 모든 거래를 기록했어요. 그날의 거래는 transactions 라는 리스트의 리스트로 제공됩니다. 각 거래는 ['coffee','gum'], ['cereal','gum'], 또는 ['bread','gum'] 중 하나예요.
이 연습은 강의의 일부입니다
Python으로 배우는 Market Basket Analysis
연습 안내
- 커피와 껌이 함께 포함된 거래 건수를 세세요.
- 시리얼과 껌이 함께 포함된 거래 건수를 세세요.
- 빵과 껌이 함께 포함된 거래 건수를 세세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Count the number of transactions with coffee and gum
coffee = transactions.count(['____', 'gum'])
# Count the number of transactions with cereal and gum
cereal = transactions.____(['cereal', 'gum'])
# Count the number of transactions with bread and gum
bread = transactions.____(['____', '____'])
# Print the counts for each transaction.
print('coffee:', coffee)
print('cereal:', cereal)
print('bread:', bread)