PHP code example of medansoftware / naive-bayes-text-classification
1. Go to this page and download the library: Download medansoftware/naive-bayes-text-classification 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/ */
medansoftware / naive-bayes-text-classification example snippets
$data = array(
array(
'text' => 'Hello, Good morning',
'class' => 'greeting'
),
array(
'text' => 'Hello, Good afternoon',
'class' => 'greeting'
),
array(
'text' => 'Hello, Good night',
'class' => 'greeting'
),
array(
'text' => 'How are you?',
'class' => 'about-me'
),
array(
'text' => 'How old are you?',
'class' => 'about-me'
),
array(
'text' => 'Where are you',
'class' => 'about-me'
),
array(
'text' => 'What\'s the time now?',
'class' => 'information-time'
),
array(
'text' => 'What\'s day today?',
'class' => 'information-time'
),
array(
'text' => 'What\'s day today?',
'class' => 'information-time'
)
);
$naive_bayes = new Algorithm\Naive_Bayes\Text_Classification;
$naive_bayes->training($data);
echo $naive_bayes->predict('Hello sir What\'s time now'); // information-time