CommencerCommencer gratuitement

Identifying frequent itemsets with Apriori

The aggregation exercise you performed for the online retailer proved helpful. It offered a starting point for understanding which categories of items appear frequently in transactions. The retailer now wants to explore the individual items themselves to find out which are frequent.

In this exercise, you'll apply the Apriori algorithm to the online retail dataset without aggregating first. Your objective will be to prune the itemsets using a minimum value of support and a maximum item number threshold. Note that pandas has been imported as pd and the one-hot encoded data is available as onehot.

Cet exercice fait partie du cours

Market Basket Analysis in Python

Afficher le cours

Instructions

  • Pass onehot to the Apriori algorithm.
  • Set the minimum support value to 0.006.
  • Set the maximum itemset length to 3.
  • Print a preview of the first five itemsets.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Import apriori from mlxtend
from mlxtend.frequent_patterns import apriori

# Compute frequent itemsets using the Apriori algorithm
frequent_itemsets = apriori(____, 
                            ____ = ____, 
                            max_len = ____, 
                            use_colnames = True)

# Print a preview of the frequent itemsets
print(____.head())
Modifier et exécuter le code