AI-NaiveBayes
view release on metacpan or search on metacpan
lib/AI/NaiveBayes/Classification.pm view on Meta::CPAN
=over 4
=item C<best_category()>
Returns a string being a label that suits given document the best.
=item C<find_predictors()>
This method returns the C<best_category()>, as well as the list of all the predictors
along with their influence on the best category selected. So the second value
returned is a list of array references, where each one contains a string being a
single feature and a number describing its influence on the result. So the
second part of the result may look like this:
(
[ 'activities', 1.2511540632952 ],
[ 'over', -1.0269523272981 ],
[ 'provide', 0.8280157033269 ],
[ 'natural', 0.7361042359385 ],
[ 'against', -0.6923354975173 ],
)
=back
lib/AI/NaiveBayes/Learner.pm view on Meta::CPAN
my @top = @features[0..$limit-1];
my %kept = map { $_ => $old{$_} } @top;
$model->{probs}{$label} = \%kept;
}
}
my $classifier_class = $self->classifier_class;
return $classifier_class->new( model => $model );
}
sub add_hash {
my ($first, $second) = @_;
$first //= {};
foreach my $k (keys %$second) {
$first->{$k} //= 0;
$first->{$k} += $second->{$k};
}
}
__PACKAGE__->meta->make_immutable;
1;
=pod
=encoding UTF-8
( run in 0.485 second using v1.01-cache-2.11-cpan-39bf76dae61 )