ComeçarComece de graça

Pruning with lift

Once again, you report back to the novelty gift store manager. This time, you tell her that you identified no rules when you used a higher support threshold for the Apriori algorithm and only two rules when you used a lower threshold. She commends you for the good work, but asks you to consider using another metric to reduce the two rules to one.

You remember that lift had a simple interpretation: values greater than 1 indicate that items co-occur more than we would expect if they were independently distributed across transactions. You decide to use lift, since that message will be simple to convey. Note that pandas is available as pd and the one-hot encoded transaction data is available as onehot. Additionally, apriori has been imported from mlxtend.

Este exercício faz parte do curso

Market Basket Analysis in Python

Ver curso

Instruções do exercício

  • Import the association_rules function from mlxtend.
  • Compute the frequent itemsets using a support of 0.001 and a maximum itemset length of 2.
  • Complete the statement to retain rules with a lift of at least 1.0.
  • Print the DataFrame of rules.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# Import the association rules function
from mlxtend.____ import ____

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

# Compute all association rules for frequent_itemsets
rules = association_rules(frequent_itemsets, 
                            metric = "____", 
                         	min_threshold = ____)

# Print association rules
print(____)
Editar e executar o código