IniziaInizia gratis

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.

Questo esercizio fa parte del corso

Market Basket Analysis in Python

Visualizza il corso

Istruzioni dell'esercizio

  • 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.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# 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())
Modifica ed esegui il codice