1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
use Algorithm::NaiveBayes;
use Data::Dumper;
#nouveau classifier
my $nb = Algorithm::NaiveBayes->new;
$nb->add_instance(attributes => {bonjour => 1, test=> 1}, label => 'Categorie1');
$nb->add_instance(attributes => {adresse=> 1, envoi=> 1}, label => 'Categorie2');
$nb->train;
my $corpusl="Bonjour, ceci est un document test";
$corpus=~s/\.\,\;\://;
my @corpus = split(/\s+/,$corpus);
my %hashCorpus = ();
foreach (@corpus){
next if($_ eq "");
$hashCorpus{$_}++;
}
my $result = $nb->predict(attributes => \%hashCorpus);
print "Resultat : ", Dumper($result), "\n"; |
Partager