2

I am a newbie in python & trying to run association rule using apriori algorithm. I have extensively done this operation using R. For the same my work-flow was;

  1. read the csv file (let df) in R
  2. create sparse/transaction matrix using 'acast' (acast(df,colA~colB))
  3. run apriori function choosing useful support lift & confidence
  4. inspect rules

For running arules in python, I searched & got to see here also I can execute the third step as I did in R. I am having problem for the second step.

What I did,searching Google,was,

import csv
file = open('file path',"rb")
csvread = csv.reader(file,delimiter=';')

Now from this 'csvread' I want to select two columns, let 'store-location' & 'item', & create a sparse matrix first, like I did in R (acast), & after that I want to run the apriori algorithm to inspect rules.

I have gone through several links but could not find the exact solution for the problem. Any suggestion that can solve my issue will be highly helpful.

Jeff
  • 2,158
  • 1
  • 16
  • 29
Hindol Ganguly
  • 363
  • 1
  • 4
  • 16
  • I'm not trying to be mean, but you say you "could not find the exact solution for the problem," and that's not what you should be looking for. You know the basic steps you need to take (like building a sparse matrix). Decide how you want to represent that and figure out how to do those smaller pieces in python. Then put them together. If you have to find the exact solution, you unfortunately won't get very far. – Millie Smith Nov 02 '16 at 13:47
  • If you're working with dataframes to do this in R, why not also use dataframes in Python? Pandas offers a sparse data structure: http://pandas.pydata.org/pandas-docs/stable/sparse.html – Jeff Nov 02 '16 at 13:49
  • may be the word 'exact' was used wrongly. but i was trying to build progressions step by step where in the second step i got stuck. – Hindol Ganguly Nov 02 '16 at 13:51
  • Fair enough. I may have taken the word "exact" too literally. I'm not the downvoter, btw. – Millie Smith Nov 02 '16 at 13:53
  • Have you looked at [SciPy](https://docs.scipy.org/doc/scipy/reference/sparse.html) yet? – Millie Smith Nov 02 '16 at 13:57
  • @MillieSmith yes I did. but could not make out much from it. both the examples, in my understanding, stand for vector operations between metrices. They do create sparse but i could not figure out how to link the process for my problem. as i said earlier, i am just a newbie. there are many experienced people here to whom this question is fairly trivial. anybody from them may downvote. i am not much concerned about that though, i want to learn :) – Hindol Ganguly Nov 02 '16 at 14:04

0 Answers0