Algorithm-Classifier-NaiveBayes

 view release on metacpan or  search on metacpan

t/01-new.t  view on Meta::CPAN

use warnings;
use Test::More;

use Algorithm::Classifier::NaiveBayes;

my $nb = Algorithm::Classifier::NaiveBayes->new;
isa_ok( $nb, 'Algorithm::Classifier::NaiveBayes', 'new' );
is( $nb->{'model'}{'lc_tokens'},      1,         'lc_tokens defaults to 1' );
is( $nb->{'model'}{'token_splitter'}, '\s+',     'token_splitter defaults to \s+' );
is( $nb->{'model'}{'stop_regex'},     undef,     'stop_regex defaults to undef' );
is( $nb->{'model'}{'total_docs'},     0,         'total_docs starts at 0' );
is( $nb->{'model'}{'smoothing'},      'laplace', 'smoothing defaults to laplace' );
is( $nb->{'model'}{'alpha'},          1,         'alpha defaults to 1 for laplace' );

my $lidstone = Algorithm::Classifier::NaiveBayes->new( 'smoothing' => 'lidstone' );
is( $lidstone->{'model'}{'smoothing'}, 'lidstone', 'smoothing arg is used' );
is( $lidstone->{'model'}{'alpha'},     0.5,        'alpha defaults to 0.5 for lidstone' );

my $lidstone_alpha = Algorithm::Classifier::NaiveBayes->new( 'smoothing' => 'lidstone', 'alpha' => 0.1 );
is( $lidstone_alpha->{'model'}{'alpha'}, 0.1, 'alpha arg is used' );



( run in 1.955 second using v1.01-cache-2.11-cpan-c966e8aa7e8 )