apriori

Get Version

0.2.2

→ ‘find item associations’

What

Ruby Apriori is a library to efficiently find item association rules within large sets of transactions. This library provides a Ruby interface to Christian Borgelt’s C implementation of this algorithm.

From Christian Borgelt’s Apriori documentation:

Association rule induction is a powerful method for so-called market basket analysis, which aims at finding regularities in the shopping behavior of customers.

With the induction of association rules one tries to find sets of products that are frequently bought together, so that from the presence of certain products in a shopping cart one can infer (with a high probability) that certain other products are present.

An association rule is a rule like “If a customer buys wine and bread, he often buys cheese, too.”

An association rule states that if we pick a customer at random and find out that he selected certain items (bought certain products, chose certain options etc.), we can be confident, quantified by a percentage, that he also selected certain other items (bought certain other products, chose certain other options etc.).

This Ruby library provides a convenient way to use this algorithm from Ruby.

Original Apriori C code by Christian Borgelt.

Installing

gem install --source http://gems.github.com jashmenn-apriori

The Algorithm:

This document is not an introduction to the Apriori algorithm. To find out more about Apriori see:

Demonstration of usage

  require 'apriori'

  transactions = [  %w{beer doritos},
                    %w{apple cheese}, 
                    %w{beer doritos}, 
                    %w{apple cheese}, 
                    %w{apple cheese}, 
                    %w{apple doritos} ]

  rules = Apriori.find_association_rules(transactions,
                            :min_items => 2,
                            :max_items => 5,
                            :min_support => 1, 
                            :max_support => 100, 
                            :min_confidence => 20)

  puts rules.join("\n")

  # Results: 
  # beer -> doritos (33.3/2, 100.0)
  # doritos -> beer (50.0/3, 66.7)
  # doritos -> apple (50.0/3, 33.3)
  # apple -> doritos (66.7/4, 25.0)
  # cheese -> apple (50.0/3, 100.0)
  # apple -> cheese (66.7/4, 75.0)

  # NOTE:
  # beer -> doritos (33.3/2, 100.0)
  # means: 
  # * beer appears in 33.3% (2 total) of the transactions (the support)
  # * beer implies doritos 100% of the time (the confidence)

See the examples directory for more examples of usage.

Rdoc

View the rdoc here

Mailing List

Rubyforge Mailing List

How to submit patches

git clone git://github.com/jashmenn/apriori.git

Build and test instructions

cd apriori
rake test
rake install_gem

add_development_dependency error

If you get the error:

undefined method `add_development_dependency' for #

This is because hoe 1.7.0 requires rubygems 1.2.0. To upgrade, simply do the following:

gem update --system

License

Apriori C code

Copyright© Christian Borgelt

Modified and under the LGPL license. See

ext/apriori/doc/copying
for details.

Ruby Apriori Extension

(The MIT License)

Copyright© 2008 Nate Murray

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Contact

Comments are welcome. Send an email to Nate Murray via the forum

Nate Murray, 18th September 2008
Theme extended from Paul Battley