import pandas as pd
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
pd.set_option('max_colwidth',100)
from mlxtend.preprocessing import TransactionEncoder
from mlxtend.frequent_patterns import apriori
def apriori_of_log(file_path,support=0.5,keys=None):
data = []
temp = open(file_path,'r').readlines()
for line in temp:
row = line.split(' ')
check = set(keys).issubset(set(row))
if check:
data.append(row)
print('clearn')
te = TransactionEncoder()
one_hot = te.fit(data).transform(data)
table = pd.DataFrame(one_hot, columns=te.columns_)
freq = apriori(table, min_support=support, use_colnames=True)
return freq.sort_values(by="support" , ascending=False).reset_index(drop=True)
apriori_of_log(file_path1,0.6,['xiaoqiang'])
apriori关联分析log日志
最新推荐文章于 2024-05-16 14:15:00 发布