PHP Classifier uses semantic versioning, it is currently at major version 0, so the public API should not be considered stable.
PHP Classifier is a text classification library with a focus on reuse, customizability and performance. Classifiers can be used for many purposes, but are particularly useful in detecting spam.
- Complement Naive Bayes Classifier
- SVM (libsvm) Classifier
- Highly customizable (easily modify or build your own classifier)
- Command-line interface via separate library (phar archive)
- Multiple data import types to get your data into the classifier (Directory of files, Database queries, Json, Serialized arrays)
- Multiple types of model caching
- Compatible with HipHop VM
$ composer require camspiers/statistical-classifierFor SVM Support both libsvm and php-svm are required. For installation intructions refer to php-svm.
useCamspiers\StatisticalClassifier\Classifier\ComplementNaiveBayes;
useCamspiers\StatisticalClassifier\DataSource\DataArray;
$source = newDataArray();
$source->addDocument('spam', 'Some spam document');
$source->addDocument('spam', 'Another spam document');
$source->addDocument('ham', 'Some ham document');
$source->addDocument('ham', 'Another ham document');
$classifier = newComplementNaiveBayes($source);
$classifier->is('ham', 'Some ham document'); // bool(true)$classifier->classify('Some ham document'); // string "ham"useCamspiers\StatisticalClassifier\Classifier\SVM;
useCamspiers\StatisticalClassifier\DataSource\DataArray;
$source = newDataArray()
$source->addDocument('spam', 'Some spam document');
$source->addDocument('spam', 'Another spam document');
$source->addDocument('ham', 'Some ham document');
$source->addDocument('ham', 'Another ham document');
$classifier = newSVM($source);
$classifier->is('ham', 'Some ham document'); // bool(true)$classifier->classify('Some ham document'); // string "ham"Caching models requires maximebf/CacheCache which can be installed via packagist. Additional caching systems can be easily integrated.
useCamspiers\StatisticalClassifier\Classifier\ComplementNaiveBayes;
useCamspiers\StatisticalClassifier\Model\CachedModel;
useCamspiers\StatisticalClassifier\DataSource\DataArray;
$source = newDataArray();
$source->addDocument('spam', 'Some spam document');
$source->addDocument('spam', 'Another spam document');
$source->addDocument('ham', 'Some ham document');
$source->addDocument('ham', 'Another ham document');
$model = newCachedModel(
'mycachename',
newCacheCache\Cache(
newCacheCache\Backends\File(
array(
'dir' => __DIR__
)
)
)
);
$classifier = newComplementNaiveBayes($source, $model);
$classifier->is('ham', 'Some ham document'); // bool(true)$classifier->classify('Some ham document'); // string "ham"useCamspiers\StatisticalClassifier\Classifier\SVM;
useCamspiers\StatisticalClassifier\Model\SVMCachedModel;
useCamspiers\StatisticalClassifier\DataSource\DataArray;
$source = newDataArray();
$source->addDocument('spam', 'Some spam document');
$source->addDocument('spam', 'Another spam document');
$source->addDocument('ham', 'Some ham document');
$source->addDocument('ham', 'Another ham document');
$model = newModel\SVMCachedModel(
__DIR__ . '/model.svm',
newCacheCache\Cache(
newCacheCache\Backends\File(
array(
'dir' => __DIR__
)
)
)
);
$classifier = newSVM($source, $model);
$classifier->is('ham', 'Some ham document'); // bool(true)$classifier->classify('Some ham document'); // string "ham"statistical-classifier/ $ composer install --dev
statistical-classifier/ $ phpunit

