mr5 / bayes
Naive bayes classifier.
dev-master
2015-07-17 10:59 UTC
Requires (Dev)
- phpunit/phpunit: ^4.7
- satooshi/php-coveralls: dev-master
This package is not auto-updated.
Last update: 2024-12-21 19:58:03 UTC
README
Usage
Add dependency to you composer.json.
"require": { "mr5/bayes":"dev-master" }
Training
<?php use Mr5\Bayes\Classifier; use Mr5\Bayes\Tokenizer\WhitespaceAndPunctuationTokenizer; use Mr5\Bayes\Storage\ArrayStorage; $storage = new ArrayStorage(); $tokenizer = new WhitespaceAndPunctuationTokenizer(); $classifier = new Classifier($storage); $classifier->learn('english', $tokenizer->tokenize('This is english')); $classifier->learn('french', $tokenizer->tokenize('Je suis Hollandais')); $probabilities = $classifier->categoriesProbability( $tokenizer->tokenize('This is a naive bayes classifier') ); var_dump($probabilities);
Will output:
array(2) {
["english"]=>
float(99.91)
["french"]=>
float(50)
}