Algorithm::Bayesian - Bayesian Spam Filtering Algorithm
use Algorithm::Bayesian; use Tie::Foo; my %storage; tie %storage, 'Tie:Foo', ...; my $b = Algorithm::Bayesian->new(\%storage); $b->spam('spamword1', 'spamword2', ...); $b->ham('hamword1', 'hamword2', ...); my $pr = $b->test('word1', 'word2', ...);
Algorithm::Bayesian provide an easy way to handle Bayesian spam filtering algorithm.
my $b = Algorithm::Bayesian->new(\%hash);
Constructor. Simple hash would be fine. You can use Tie::DBI to store data to RDBM, or other key-value storage.
my $num = $b->getHam($word);
Get $word count in Ham.
$word
my $num = $b->getSpam($word);
Get $word count in Spam.
$b->ham(@words);
Train @words as Ham.
@words
$b->spam(@words);
Train @words as Spam.
my $pr = $b->test(@words);
Calculate the spam probability of @words. The range of $pr will be in 0 to 1.
$pr
my $pr = $b->testWord($word);
Calculate the spam probability of $word.
The range of $pr will be in 0 to 1. For non-existence word, it will be 0.5.
Gea-Suan Lin, <gslin at gslin.org>
<gslin at gslin.org>
Copyright 2010 Gea-Suan Lin.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Algorithm::Bayesian, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Algorithm::Bayesian
CPAN shell
perl -MCPAN -e shell install Algorithm::Bayesian
For more information on module installation, please visit the detailed CPAN module installation guide.