my $positive = {
word1 => 2,
word2 => 4,
word3 => 1,
};
my $negative = {
word4 => 3,
word5 => 1,
};
####
my $categorizer = Algorithm::NaiveBayes->new;
$categorizer->add_instance(
attributes => $positive,
label => 'positive');
$categorizer->add_instance(
attributes => $negative,
label => 'negative');
$categorizer->train;
####
my $sentence1 = {
wordA => 2,
wordB => 1,
};
my $probability = $categorizer->predict(attributes => $sentence1);
if ($probability->{'positive'} > 0.5) {
# sentence1 probably positive
}
elsif ($probability->{'negative'} > 0.5) {
# sentence1 probably negative
}