ID3

NAME

Acme::Skynet::ID3

DESCRIPTION

Acme::Skynet::ID3 is a basic implementation for generating an ID3 tree.

Examples

use v6;
    use Acme::Skynet::ID3;
# We need to create a thingy so our classifier and
    # thingy can talk and read each other
class FeatNum does Featurized {
      has $.value;
      method new($value){
        self.bless(:$value);
      }
      method getFeature($feature) {
        return ($.value % 2 == 0);
      }
      # In training, label known, when querying,
      # this isn't used and can be left blank
      method getLabel() {
        return (($.value %2 == 0)) ?? "even" !! "odd";
      }
    }
my $Classifier = ID3Tree.new();
    my @features = "value";
    my @labels = "even", "odd";
    $Classifier.setFeatures(@features);
    $Classifier.setLabels(@labels);
    for [1..10] -> $num {
      $Classifier.addItem(FeatNum.new($num));
    }
    $Classifier.learn();
say $Classifier.get(FeatNum.new(100); # => "even"
    say $Classifier.get(FeatNum.new(99)); # => "odd"

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.