FPmax算法Python实现例子
import copy
import pandas as pd
from mlxtend.frequent_patterns import fpmax
from mlxtend.preprocessing import TransactionEncoder
def FPmax_deal(data):
return data.dropna().tolist()
def FPmax(data,min_support):
temp_df=pd.DataFrame(data)
df_arr = temp_df.apply(FPBS_deal,axis=1).tolist()
te = TransactionEncoder()
df_tf = te.fit_transform(df_arr)
transact_items_matrix = pd.DataFrame(df_tf,columns=te.columns_)
rule_items=fpmax(transact_items_matrix,min_support=min_support,use_colnames=True)
print(rule_items)
if __name__ == '__main__':
test_list = [[1,3,4],
[2,3,5],
[1,2,3,5],
[2,5],
[1,2,3,5]]
FPBS(test_list,0.4)
|