MulaiMulai sekarang secara 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.

Latihan ini adalah bagian dari kursus

Market Basket Analysis in Python

Lihat Kursus

Petunjuk latihan

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

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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())
Edit dan Jalankan Kode