0
def perform_rule_calculation(transact_items_matrix, rule_type="fpgrowth", min_support=0.001):
    
    start_time = 0
    total_execution = 0
    
    if(not rule_type=="fpgrowth"):
        start_time = time.time()
        rule_items = apriori(transact_items_matrix, 
                       mini_support=min_support, 
                       use_colnames=True, low_memory=True)
        total_execution = time.time() - start_time
        print("Computed Apriori!")
        
    n_range = range(1, 10, 1)
   list_time_ap = []
   list_time_fp = []
for n in n_range:
    time_ap = 0
    time_fp = 0
    min_sup = float(n/100)
    time_ap = perform_rule_calculation(trans_encoder_matrix, rule_type="fpgrowth", min_support=min_sup)
    time_fp = perform_rule_calculation(trans_encoder_matrix, rule_type="aprior", min_support=min_sup)
    list_time_ap.append(time_ap)
    list_time_fp.append(time_fp)

这是关于先验与 FP 增长算法的教程,这里的问题是在先验中计算最小支持我得到了这个错误。我该如何解决这个问题?

4

1 回答 1

0

它只是一个错字。您在生成规则时输入了 mini 而不是 min。我在下面更正了

def perform_rule_calculation(transact_items_matrix, rule_type="fpgrowth", min_support=0.001):
    
    start_time = 0
    total_execution = 0
    
    if(not rule_type=="fpgrowth"):
        start_time = time.time()
        rule_items = apriori(transact_items_matrix, 
                       min_support=min_support, 
                       use_colnames=True, low_memory=True)
        total_execution = time.time() - start_time
        print("Computed Apriori!")
        
    n_range = range(1, 10, 1)
   list_time_ap = []
   list_time_fp = []
for n in n_range:
    time_ap = 0
    time_fp = 0
    min_sup = float(n/100)
    time_ap = perform_rule_calculation(trans_encoder_matrix, rule_type="fpgrowth", min_support=min_sup)
    time_fp = perform_rule_calculation(trans_encoder_matrix, rule_type="aprior", min_support=min_sup)
    list_time_ap.append(time_ap)
    list_time_fp.append(time_fp)
于 2021-06-07T11:32:38.530 回答