import pandas as pd
from apyori import apriori
from collections import defaultdict
ds=pd.read_csv('event.csv',header=None)
num_records=len(ds)
print(num_records)
records=[]
for i in range(0,num_records):
records.append([str(ds.values[i,j])for j in range(0,6)])
association_rule=apriori(records,min_support=0.01,min_confidence=0.50,min_lift=8,min_length=2)
association_Results=list(association_rule)
print(association_Results)
results=[]
for item in association_Results:
pair = item[0]
items=[x for x in pair]
value0=str(item[0])
value1=str(item[1])
value2=str(item[1])[:7]
value3=str(item[2][0][2])[:7]
rows=[value0,value1,value2,value3]
results.append(rows)
#print(value0)
#print(results)
label=['Tracks','Support','confidence','Lift']
Event_suggestion =pd.DataFrame.from_records(results,columns=label)
print(Event_suggestion)
k=Event_suggestion.iloc[0]['Tracks']
print(next(value for value in k))
результат: 1001 треков ... Поднимите 0 frozenset ({'ART', 'Digital Marketing'}) ... 1.0
[1 rows x 4 columns]
Tracks ... Lift
0 frozenset({'ART', 'Digital Marketing'}) ... 1.0
1 frozenset({'IOT', 'Public Speaking'}) ... 0.83333
[2 rows x 4 columns]
Tracks ... Lift
0 frozenset({'ART', 'Digital Marketing'}) ... 1.0
1 frozenset({'IOT', 'Public Speaking'}) ... 0.83333
2 frozenset({'IOT', 'Public Speaking', 'Finance'}) ... 0.6875
[3 rows x 4 columns]
f
[Finished in 0.9s]
** этот код предназначен для предлагаемых событий с использованием алгоритма Apriori. Он берет дорожки из событий и видит частый элемент или элементы и предлагает **