0

I have a dataset like this:

id|kurs|grade
1|c1|a
1|c2|b
2|c3|a

I want to mine association rules in such a way.If one gets a grade 'a' in 'c1',he would get 'b' in c2.This is just an example,but I want to mine association rules in such a way. I have tried the following code:

dataset=list(df.values)
te = TransactionEncoder()
te_ary = te.fit(dataset).transform(dataset)
df_encoded = pd.DataFrame(te_ary, columns=te.columns_)
df_encoded
from mlxtend.frequent_patterns import apriori

apriori(df_encoded, min_support=0.1,use_colnames=True)

I did not get the expected output.Could you throw some light on it?

martineau
  • 119,623
  • 25
  • 170
  • 301
Sri Test
  • 389
  • 1
  • 4
  • 21

1 Answers1

0

You should preprocess the data so it fits the format that is expected. Try

#create example dataframe
import pandas as pd
ids = [1,1,2,2,3]
kurs= [1,2,3,1,1]
grade=[1,1,2,2,1]
df=pd.DataFrame.from_dict({'id':ids, 'kurs':kurs, 'grade':grade})
# make it in into the expected format 
df_properly = pd.crosstab(df['id'],[df['kurs'],df['grade']])
Feelx234
  • 310
  • 1
  • 7