ComeçarComece de graça

Generating association rules

In the final exercise of the previous section, you computed itemsets for the novelty gift store owner using the Apriori algorithm. You told the store owner that relaxing support from 0.005 to 0.003 increased the number of itemsets from 9 to 91. Relaxing it again to 0.001 increased the number to 429. Satisfied with the descriptive work you've done, the store manager asks you to identify some association rules from those two sets of frequent itemsets you computed.

Note that pandas has been imported for you as pd and the two frequent itemsets are available as frequent_itemset_1 and frequent_itemset_2. Your objective is to determine what association rules can be mined from these itemsets.

Este exercício faz parte do curso

Market Basket Analysis in Python

Ver curso

Instruções do exercício

  • Import the algorithm from mlxtend that computes association rules from apriori algorithm results.
  • Complete the statement to compute association rules for frequent_itemsets_1 using the support metric and a threshold of 0.0015.
  • Complete the statement to compute association rules for frequent_itemsets_2 using the support metric and a threshold of 0.0015.

Exercício interativo prático

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

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

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

# Compute all association rules for frequent_itemsets_2
rules_2 = association_rules(frequent_itemsets_2, 
                            metric = ____, 
                        	____)

# Print the number of association rules generated
print(len(rules_1), len(rules_2))
Editar e executar o código