A Naive Bayesian Classifier in Clojure
Clojure
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src/bayesian_classifier
test/bayesian_classifier/test
.gitignore
README
project.clj

README

# bayesian-classifier

A naive bayesian classifier supporting both traditional classification and Paul Graham's variant outlined in "A Plan for Spam"

## Usage

make-classifier accepts N category names as keywords and returns a classifer:
(def *healthy-sick-classifier* (make-classifier :healthy :sick))

If you wish to use agents or atoms for your concurrency mechanism then by all means, do this:
(def *healthy-sick-classifier-atom* (atom (make-classifier :healthy :sick))
(def *healthy-sick-classifier-agent* (agent (make-classifier :healthy :sick))

Next, you'll want to give it some training data. learn! will throw an exception if you attempt to
classify data into a concept/class that is currently not in the classifer.  learn will just roll with this
and create the new concept/class on the fly.

(learn! *healthy-sick-classifier* "fred" :sick)
(swap! learn! *healthy-sick-classifier* "fred" :sick)
(send *healthy-sick-classifier-agent* learn! "fred" :first)

Use one of the support methods to categorize new data. These classifications algo's utilize protocols
to ensure type transparency.  They will work seemless with vanilla classifier maps, atoms or agents:
(p-of-class-given-token *healthy-sick-classifier* "betty")
(p-of-class-given-token-graham *healthy-sick-classifier* "mary")

Persisting trained classifiers is trivial:
(save-classifier *healthy-sick-classifer* "chicken.txt")
(load-classifier "chicken.txt")

## Installation

Typical leiningen project rules apply.

## License

Copyright (C) 2010 Do What Thou Wilt Shall Be The Whole Of The Law.