3
$\begingroup$

I am preparing a lecture on data mining algorithms in R and I want to demonstrate the famous Apriori algorithm in it.

My question
Could anybody point me to a simple implementation of this algorithm in R?

(I am not looking for a package, e.g. arules, but for comprehensible source code of an implementation from scratch. It also does not help to look at the source code of arules: It just calls a C implementation of the algorithm!)

$\endgroup$
2
$\begingroup$

Have you checked the following reference out? Link: http://www.borgelt.net/docs/apriori.pdf

The above link has the explanation along with the code.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Yes, I have seen it. You link does not work by the way. $\endgroup$ – vonjd Sep 10 '15 at 6:18
  • $\begingroup$ This is the author of the C library that is being used by the arules package btw. $\endgroup$ – vonjd Sep 10 '15 at 7:42
  • $\begingroup$ My bad, not sure how [1] got appended at the end. The idea with sharing this implementation( as implemented in the arules pkg) was the explanation stated along the side. Using that one can write the same in R. What do you think ? I read more into your question. Let me see if i can help you out more. $\endgroup$ – Pramit Sep 10 '15 at 18:10
  • $\begingroup$ Would you be able to write it in R? It seems pretty involved... $\endgroup$ – vonjd Sep 10 '15 at 19:58
  • 1
    $\begingroup$ I think @vonjd just needs a simple implementation to demonstrate the algorithm, just a prototype. $\endgroup$ – Pramit Sep 14 '15 at 16:21
2
$\begingroup$

I found an implementation here: Learning Data Mining with R by Bater Makhabel

The source code can be downloaded here: https://www.packtpub.com/big-data-and-business-intelligence/learning-data-mining-r

| improve this answer | |
$\endgroup$
  • $\begingroup$ It's walled, requires registration. How does it benchmark, compared to e.g. arules, on some classic benchmark sets? $\endgroup$ – Has QUIT--Anony-Mousse Sep 14 '15 at 9:42
  • $\begingroup$ @Anony-Mousse: I haven't benchmarked it but I expect it to be considerably slower because arules calls, as I wrote in my question, a compiled C implementation. $\endgroup$ – vonjd Sep 14 '15 at 13:11
  • $\begingroup$ Yes, but it would be good to be able to put a number on that. Two orders of magnitude, or four? Because in my experience, plain R code is incredibly slow (so it does not make sense to even start implementing such algorithms in R in my opinion). $\endgroup$ – Has QUIT--Anony-Mousse Sep 14 '15 at 13:16
  • $\begingroup$ @Anony-Mousse: It can make sense for pedagogical reasons, to understand the underlying concepts and algorithms. $\endgroup$ – vonjd Sep 14 '15 at 13:18
  • 2
    $\begingroup$ I disagree. It only teaches them to use the wrong tools the wrong way. You are better off using pseudocode that doesn't bother with irrelevant syntax hacks necessary to make it work in R. Your students will be fighting with R code they'll never use, and miss the subtle details of Apriori. I just had a look at this Apriori implementation, and it already lacks some of these simple yet efficient optimizations that simply exploit the sortedness and drastically reduce the apriori-gen cost. Focus on the key ideas of generating as few candidates, and clever pruning instead. $\endgroup$ – Has QUIT--Anony-Mousse Sep 14 '15 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.