image_output_1.png
from mlxtend.frequent_patterns import apriori, association_rules,fpgrowth,fpmax

def compute_association_rule(rule_matrix, metric='lift', min_thresh=1):
    """
    Compute the final association rule
        rule_matrix: the corresponding algorithms matrix
        metric: the metric to be used (default is lift)
        min_thresh: the minimum threshold (default is 1)
    Returns
        Rules:: Information for each transaction satisfying the given metric & threshold
    """
    rules = association_rules(rule_matrix, metric=metric, min_threshold=min_thresh)
    return rules

apripri_rule = compute_association_rule(apriori_matrix, metric='confidence', min_thresh=0.2)
apripri_rule.head()