Git Product home page Git Product logo

bayes_motel's Introduction

bayes_motel

BayesMotel is a multi-variate Bayesian classification engine. There are two steps to Bayesian classification:

  1. Training You provide a set of variables along with the proper classification for that set.
  2. Runtime You provide a set of variables and ask for the proper classification according to the training in Step 1.

Commonly this is used for spam detection. You will provide a corpus of emails or other data along with a "Spam/NotSpam" classification. The library will determine which variables affect the classification and use that to judge future data.

Usage

Step one is to create a corpus that you can train with a set of previously classified documents:

corpse = BayesMotel::Corpus.new('tweets')
spam_tweets.each do |tweet|
  corpse.train(tweet, :spam)
end
good_tweets.each do |tweet|
  corpse.train(tweet, :ham)
end
corpse.cleanup

In this example, we have a set of spammy tweets and a set of known good tweets. We pass in each tweet to our train() method. Once we have completed training, we call cleanup which will run through the internal data structures and clean up any variables that are too 'unique' to make a difference in classification (for instance, an :id variable will be unique for each tweet and so will be removed in the cleanup since it does not repeat enough times).

Step two is to use the calculated corpus for the category scores or a classification for a given document:

corpse.scores(new_tweet)
=> { :spam => 12.4, :ham => 15.25 }
corpse.classify(new_tweet)
=> [:ham, 15.25]

Trivia

Bates Motel is the motel in Alfred Hitchcock's masterpiece Psycho. Corpus is Latin for "body" but also means 'a canonical set of documents'. I'm not crazy, I just like puns.

Author

Mike Perham, mperham AT gmail.com, @mperham, http://mikeperham.com

Copyright

Copyright (c) 2010 Mike Perham. See LICENSE for details.

bayes_motel's People

Contributors

mperham avatar jmdeldin avatar aseever avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.