++ed by:
Koichi SATOH

NAME

Algorithm::AdaBoost - AdaBoost learning algorithm

SYNOPSIS

  use Algorithm::AdaBoost;

  # Training phase.
  my $learner = Alogrithm::AdaBoost->new(
    training_set => [
      +{ feature => [...], label => 1, },
      +{ feature => [...], label => -1, },
      +{ feature => [...], label => -1, },
      ...
    ],
    weak_classifier_generator => \&my_poor_learning_algorithm,
  );
  $learner->train(num_iterations => 1_000);

  # Now you have a boost-ed classifier (Algorithm::AdaBoost::Classifier).
  my $classifier = $learner->final_classifier;
  given ($classifier->classify([...])) {
    when ($_ > 0) { say 'The data belongs to class 1.' }
    when ($_ < 0) { say 'The data belongs to class 2.' }
    default { warn 'The data cannot be classified.' }
  }

DESCRIPTION

AdaBoost is a machine learning algorithm proposed by Freund and Schapire. Using an arbitrary binary classification algorithm, The algorithm can construct a more accurate classifier (i.e. it is a meta-algorithm).

METHODS

new

Constructor. You can specify 2 optional attributes:

training_set

An ArrayRef which is used as a training data set.

Each item is a HashRef having 2 keys: feature and label. feature is a arbitrary input that classifier accepts and label is a expected output label (+1 or -1).

weak_classifier_generator

A CodeRef which is expected to generate a binary classifier function.

When the function is called, 2 named parameters are specified like this:

  my $classifier = $generator->(
     distribution => [...],
     training_set => [...],
  );

distribution is an ArrayRef which each item is a probability of corresponding item in training_set. i.e. distribution is P(X = t_i) where t_i is i-th item in training_set.

The generated classifier is expected to be a CodeRef which takes 1 argument (value of feature) and return +1 or -1 as a output label.

Either of both can be overriden temporarily with parameters for train.

classify

Shorthand for $learner->final_classifier->classify.

final_classifier

Returns the last constructed classifier.

train

Constructs a stronger classifier from given training set and weak learning algorithm.

This method takes 1 mandatory parameter:

num_iterations

Specifies how many training iterations to be excuted (i.e., how many weak classifiers to be generated).

and 2 optional parameters:

training_set
weak_classifier_generator

If the optional parameters are ommited, parameters specified to new are used as defaults. If constructor parameters are ommited too, an exception will be raised.

trained

True if train method have called, false otherwise.

AUTHOR

Koichi SATOH <sekia@cpan.org>

SEE ALSO

A Short Introduction to Boosting

LICENSE

The MIT License

Copyright (C) 2012 by Koichi SATOH

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.




Hosting generously
sponsored by Bytemark