NAME

Redis::Bayes - Bayesian classification on Redis

SYNOPSIS

EXAMPLES:

  my $rb = Redis::Bayes->new;
  $rb->train('apple_computer',q{I'm going to pick up a new retina display MacBook!});
  $rb->train('apple_fruit',q{That thing is rotten at the seeds.});
  my $result = $rb->classify("retina display");

DESCRIPTION

This module is an implementation of naive Bayes on Redis.

METHODS

new

  my $rb = Redis::Bayes->new; # defaults to Redis->new(reconnect => 2, every => 100);
  # or
  my $rb = Redis::Bayes->new(
    prefix => 'yourownprefixhere:',
    stopwords => {blah => 1, whatever => 1},
    tokenizer => \&tokenize,
    redis => $redis,
  );
prefix

Redis database prefix. The default is 'bayes:'.

stopwords

The set of words to filter when training. The default uses Lingua::StopWords.

tokenizer

The package is equipped with its own tokenizer. But you may override this by supplying your own as a coderef either at creation or after instantiation.

redis

Defaults to Redis->new(reconnect => 2, every => 100). Otherwise, use delegation here.

train

  $rb->train('apple','sauce');

Train using <label, document>.

untrain

  $rb->untrain('apple','sauce');

Untrains <label, document>.

flush

  $rb->flush;

Flushes all trained data.

classify

  $rb->classify(q{there's a computer on the desk});

Returns the label with the highest confidence metric for the given document.

SEE ALSO

Redis

ACKNOWLEDGEMENTS

This module is ported loosely from other such packages in node and python, i.e. https://github.com/harthur/classifier and https://github.com/jart/redisbayes and https://github.com/didip/bayes_on_redis, with some modifications.

AUTHOR

Andrew Shapiro, <trski@cpan.org>

BUGS

Please report any bugs or feature requests to bug-redis-bayes at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Redis-Bayes. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

LICENSE AND COPYRIGHT

Copyright 2014 Andrew Shapiro.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information.