The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

AI::NaiveBayes::Learner - Build AI::NaiveBayes classifier from a set of training examples.

VERSION

version 0.04

SYNOPSIS

my $learner = AI::NaiveBayes::Learner->new(features_kept => 0.5);
$learner->add_example(
    attributes => { sheep => 1, very => 1, valuable => 1, farming => 1 },
    labels => ['farming'] 
);

my $classifier = $learner->classifier;

DESCRIPTION

This is a trainer of AI::NaiveBayes classifiers. It saves information passed by the add_example method from training data into internal structures and then constructs a classifier when the classifier method is called.

ATTRIBUTES

features_kept

Indicates how many features should remain after calculating probabilities. By default all of them will be kept. For features_kept > 1, features_kept of features will be preserved. For values lower than 1, a specified fraction of features will be kept (e.g. top 20% of features for features_kept = 0.2).

The rest of the attributes is for class' internal usage, and thus not documented.

classifier_class

The class of the classifier to be created. By default it is AI::NaiveBayes

METHODS

add_example( attributes = HASHREF, labels => LIST )>

Saves the information from a training example into internal data structures. attributes should be of the form of { feature1 => weight1, feature2 => weight2, ... } labels should be a list of strings denoting one or more classes to which the example belongs.

classifier()
Creates an AI::NaiveBayes classifier based on the data accumulated before.

UTILITY SUBS

add_hash

BASED ON

Much of the code and description is from Algorithm::NaiveBayes.

AUTHORS

  • Zbigniew Lukasiak <zlukasiak@opera.com>

  • Tadeusz Sośnierz <tsosnierz@opera.com>

  • Ken Williams <ken@mathforum.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Opera Software ASA.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.