Introduction To Market Basket Analysis in Python - Practical Business Python
Introduction To Market Basket Analysis in Python - Practical Business Python
html
1 de 12 01/12/2017 10:35 a. m.
Introduction to Market Basket Analysis in Python - Practical Business P... http://pbpython.com/market-basket-analysis.html
2 de 12 01/12/2017 10:35 a. m.
Introduction to Market Basket Analysis in Python - Practical Business P... http://pbpython.com/market-basket-analysis.html
3 de 12 01/12/2017 10:35 a. m.
Introduction to Market Basket Analysis in Python - Practical Business P... http://pbpython.com/market-basket-analysis.html
import pandas as pd
from mlxtend.frequent_patterns import apriori
from mlxtend.frequent_patterns import association_rules
df = pd.read_excel('http://archive.ics.uci.edu/ml/machine-learning-databases/00352/Online%20Retail
df.head()
4 de 12 01/12/2017 10:35 a. m.
Introduction to Market Basket Analysis in Python - Practical Business P... http://pbpython.com/market-basket-analysis.html
df['Description'] = df['Description'].str.strip()
df.dropna(axis=0, subset=['InvoiceNo'], inplace=True)
df['InvoiceNo'] = df['InvoiceNo'].astype('str')
df = df[~df['InvoiceNo'].str.contains('C')]
5 de 12 01/12/2017 10:35 a. m.
Introduction to Market Basket Analysis in Python - Practical Business P... http://pbpython.com/market-basket-analysis.html
def encode_units(x):
if x <= 0:
return 0
if x >= 1:
return 1
basket_sets = basket.applymap(encode_units)
basket_sets.drop('POSTAGE', inplace=True, axis=1)
6 de 12 01/12/2017 10:35 a. m.
Introduction to Market Basket Analysis in Python - Practical Business P... http://pbpython.com/market-basket-analysis.html
apriori
association_rules
7 de 12 01/12/2017 10:35 a. m.
Introduction to Market Basket Analysis in Python - Practical Business P... http://pbpython.com/market-basket-analysis.html
340.0
316.0
basket_sets2 = basket2.applymap(encode_units)
basket_sets2.drop('POSTAGE', inplace=True, axis=1)
frequent_itemsets2 = apriori(basket_sets2, min_support=0.05, use_colnames=True)
rules2 = association_rules(frequent_itemsets2, metric="lift", min_threshold=1)
8 de 12 01/12/2017 10:35 a. m.
Introduction to Market Basket Analysis in Python - Practical Business P... http://pbpython.com/market-basket-analysis.html
Vote 3 Share 89
3 points
9 de 12 01/12/2017 10:35 a. m.
Introduction to Market Basket Analysis in Python - Practical Business P... http://pbpython.com/market-basket-analysis.html
LOG IN WITH
OR SIGN UP WITH DISQUS ?
10 de 12 01/12/2017 10:35 a. m.
Introduction to Market Basket Analysis in Python - Practical Business P... http://pbpython.com/market-basket-analysis.html
11 de 12 01/12/2017 10:35 a. m.
Introduction to Market Basket Analysis in Python - Practical Business P... http://pbpython.com/market-basket-analysis.html
12 de 12 01/12/2017 10:35 a. m.