naive_bayes v0.1.2 NaiveBayes

An implementation of Naive Bayes

Summary

Functions

Set the assume_uniform constant

Returns a list of probabilities of classes given a list of tokens

Initializes a new NaiveBayes agent

Allows removal of low frequency words that increase processing time and may overfit

Increase smoothing constant to dampen the effect of the rare tokens

Trains the naive bayes instance given a list of tokens and categories

Functions

assume_uniform(pid, bool)

Set the assume_uniform constant.

Returns {:ok}

Examples

iex> nbayes |> NaiveBayes.assume_uniform(true)
:ok
classify(pid, tokens)

Returns a list of probabilities of classes given a list of tokens.

Examples

iex> results = nbayes |> NaiveBayes.classify( ["a", "b", "c"] )
%{"HAM" => 0.4832633319857435, "SPAM" => 0.5167366680142564}
new(opts \\ [])

Initializes a new NaiveBayes agent

Returns {:ok, pid}.

Examples

iex> {:ok, nbayes} = NaiveBayes.new(binarized: false, assume_uniform: true, smoothing: 2)
{:ok, #PID<0.137.0>}
purge_less_than(pid, x)

Allows removal of low frequency words that increase processing time and may overfit

Returns {:ok}

Examples

iex> nbayes |> NaiveBayes.purge_less_than(5)
:ok
set_smoothing(pid, x)

Increase smoothing constant to dampen the effect of the rare tokens

Returns {:ok}

Examples

iex> nbayes |> NaiveBayes.set_smoothing(2)
:ok
train(pid, tokens, categories)

Trains the naive bayes instance given a list of tokens and categories

Returns {:ok} or {:error}

Examples

iex> {:ok, nbayes} = NaiveBayes.new
{:ok, #PID<0.137.0>}
iex> nbayes |> NaiveBayes.train( ["a", "b", "c"], "classA" )
{:ok}