8. Market Basket Analysis
Activity 8.01: Loading and Preparing Full Online Retail Data
Solution:
- Import the required libraries:
import matplotlib.pyplot as plt import mlxtend.frequent_patterns import mlxtend.preprocessing import numpy import pandas
- Load the online retail dataset file:
online = pandas.read_excel(io="./Online Retail.xlsx", \ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â sheet_name="Online Retail", \ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â header=0)
- Clean and prep the data for modeling, including turning the cleaned data into a list of lists:
online['IsCPresent'] = (online['InvoiceNo'].astype(str)\ Â Â Â Â Â Â Â Â Â Â Â Â Â Â ...