import numpy as np import matplotlib.pyplot as plt import pandas as pd dataset = pd.read_csv('E:\Program Files (x86)\Apriori-Association-Rules-main\Market_Basket_Optimisation.csv', header = None) print(dataset) transactions = [] for i in range(0, 7501): transactions.append([str(dataset.values[i,j]) for j in range(0, 20)]) print(transactions)如何压缩输出结果
时间: 2024-03-14 18:43:30 浏览: 164
import numpy as np import matplotlib.pyplot as plt import math
可以通过遍历输出结果中的每个关联规则,并只输出其中的部分信息来压缩输出结果。例如,可以只输出规则的前件和后件,以及置信度和提升度等信息。以下是一个示例代码:
```
from apyori import apriori
rules = apriori(transactions, min_support = 0.003, min_confidence = 0.2, min_lift = 3, min_length =2)
for rule in rules:
# 输出规则的前件和后件
print(list(rule.items_base), "->", list(rule.items_add))
# 输出规则的置信度和提升度
print("Confidence:", rule.ordered_statistics[0].confidence)
print("Lift:", rule.ordered_statistics[0].lift)
print("-----------------------------")
```
这样可以只输出每个关联规则的关键信息,从而压缩输出结果。
阅读全文