PHP code example of assisted-mindfulness / naive-bayes

1. Go to this page and download the library: Download assisted-mindfulness/naive-bayes library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

assisted-mindfulness / naive-bayes example snippets


$classifier = new Classifier();

$classifier
    ->learn('I love sunny days', 'positive')
    ->learn('I hate rain', 'negative');

$classifier->most('is a sunny days'); // positive
$classifier->most('there will be rain'); // negative

$classifier->guess('is a sunny days');

/*
items: array:2 [
  "positive" => 0.0064
  "negative" => 0.0039062
]
*/

$classifier
   ->uneven()
   ->guess('is a sunny days');

$classifier = new Classifier();

$classifier->setTokenizer(function (string $string) {
    return Str::of($string)
        ->lower()
        ->matchAll('/[[:alpha:]]+/u')
        ->filter(fn (string $word) => Str::length($word) > 3);
});