PHPackages                             jamesfrost/statistical-classifier - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jamesfrost/statistical-classifier

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jamesfrost/statistical-classifier
=================================

A PHP implementation of Complement Naive Bayes and SVM statistical classifiers, including a structure for building other classifier, multiple data sources and multiple caching backends

0.9.0(9y ago)12.7k1MITPHPPHP &gt;=5.3.3

Since Mar 14Pushed 9y ago1 watchersCompare

[ Source](https://github.com/JamesFrost/statistical-classifier)[ Packagist](https://packagist.org/packages/jamesfrost/statistical-classifier)[ Docs](http://php-classifier.com/)[ RSS](/packages/jamesfrost-statistical-classifier/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (5)Versions (23)Used By (0)

PHP Classifier
==============

[](#php-classifier)

[![Build Status](https://camo.githubusercontent.com/6d625287930108b9eb83d99f9387579dccb2b4c359b2a616b2960c377497ea72/68747470733a2f2f7472617669732d63692e6f72672f63616d7370696572732f737461746973746963616c2d636c61737369666965722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/camspiers/statistical-classifier)[![Latest Stable Version](https://camo.githubusercontent.com/4c9e01e81822a81df481fb3be025d33b256e9a69c1f301c87254ad58be846585/68747470733a2f2f706f7365722e707567782e6f72672f63616d7370696572732f737461746973746963616c2d636c61737369666965722f762f737461626c652e706e67)](https://packagist.org/packages/camspiers/statistical-classifier)

PHP Classifier uses [semantic versioning](http://semver.org/), it is currently at major version 0, so the public API should not be considered stable.

What is it?
===========

[](#what-is-it)

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.

Features
--------

[](#features)

- 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

Installation
============

[](#installation)

```
$ composer require camspiers/statistical-classifier
```

SVM Support
-----------

[](#svm-support)

For SVM Support both libsvm and php-svm are required. For installation intructions refer to [php-svm](https://github.com/ianbarber/php-svm).

Usage
=====

[](#usage)

Non-cached Naive Bayes
----------------------

[](#non-cached-naive-bayes)

```
use Camspiers\StatisticalClassifier\Classifier\ComplementNaiveBayes;
use Camspiers\StatisticalClassifier\DataSource\DataArray;

$source = new DataArray();
$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 = new ComplementNaiveBayes($source);
$classifier->is('ham', 'Some ham document'); // bool(true)
$classifier->classify('Some ham document'); // string "ham"
```

Non-cached SVM
--------------

[](#non-cached-svm)

```
use Camspiers\StatisticalClassifier\Classifier\SVM;
use Camspiers\StatisticalClassifier\DataSource\DataArray;

$source = new DataArray()
$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 = new SVM($source);
$classifier->is('ham', 'Some ham document'); // bool(true)
$classifier->classify('Some ham document'); // string "ham"
```

Caching models
==============

[](#caching-models)

Caching models requires [maximebf/CacheCache](https://github.com/maximebf/CacheCache) which can be installed via packagist. Additional caching systems can be easily integrated.

Cached Naive Bayes
------------------

[](#cached-naive-bayes)

```
use Camspiers\StatisticalClassifier\Classifier\ComplementNaiveBayes;
use Camspiers\StatisticalClassifier\Model\CachedModel;
use Camspiers\StatisticalClassifier\DataSource\DataArray;

$source = new DataArray();
$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 = new CachedModel(
	'mycachename',
	new CacheCache\Cache(
		new CacheCache\Backends\File(
			array(
				'dir' => __DIR__
			)
		)
	)
);

$classifier = new ComplementNaiveBayes($source, $model);
$classifier->is('ham', 'Some ham document'); // bool(true)
$classifier->classify('Some ham document'); // string "ham"
```

Cached SVM
----------

[](#cached-svm)

```
use Camspiers\StatisticalClassifier\Classifier\SVM;
use Camspiers\StatisticalClassifier\Model\SVMCachedModel;
use Camspiers\StatisticalClassifier\DataSource\DataArray;

$source = new DataArray();
$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 = new Model\SVMCachedModel(
	__DIR__ . '/model.svm',
	new CacheCache\Cache(
		new CacheCache\Backends\File(
			array(
				'dir' => __DIR__
			)
		)
	)
);

$classifier = new SVM($source, $model);
$classifier->is('ham', 'Some ham document'); // bool(true)
$classifier->classify('Some ham document'); // string "ham"
```

Unit testing
============

[](#unit-testing)

```
statistical-classifier/ $ composer install --dev
statistical-classifier/ $ phpunit

```

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~63 days

Recently: every ~265 days

Total

22

Last Release

3533d ago

PHP version history (2 changes)0.1.0PHP &gt;=5.3.0

0.4.0PHP &gt;=5.3.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6696197?v=4)[James Frost](/maintainers/JamesFrost)[@JamesFrost](https://github.com/JamesFrost)

---

Top Contributors

[![camspiers](https://avatars.githubusercontent.com/u/51294?v=4)](https://github.com/camspiers "camspiers (131 commits)")[![JamesFrost](https://avatars.githubusercontent.com/u/6696197?v=4)](https://github.com/JamesFrost "JamesFrost (10 commits)")[![khromov](https://avatars.githubusercontent.com/u/1207507?v=4)](https://github.com/khromov "khromov (3 commits)")[![sasezaki](https://avatars.githubusercontent.com/u/42755?v=4)](https://github.com/sasezaki "sasezaki (1 commits)")

---

Tags

bayesclassifiersvmnaive

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jamesfrost-statistical-classifier/health.svg)

```
[![Health](https://phpackages.com/badges/jamesfrost-statistical-classifier/health.svg)](https://phpackages.com/packages/jamesfrost-statistical-classifier)
```

###  Alternatives

[camspiers/statistical-classifier

A PHP implementation of Complement Naive Bayes and SVM statistical classifiers, including a structure for building other classifier, multiple data sources and multiple caching backends

17037.0k1](/packages/camspiers-statistical-classifier)[symfony/ux-toggle-password

Toggle visibility of password inputs for Symfony Forms

27571.2k5](/packages/symfony-ux-toggle-password)[symfony/ux-cropperjs

Cropper.js integration for Symfony

19322.9k3](/packages/symfony-ux-cropperjs)[2lenet/crudit-bundle

The easy like Crud'it Bundle.

1615.6k12](/packages/2lenet-crudit-bundle)[fieg/bayes

Implementation of Naive Bayes Classifier algorithm in PHP.

7094.7k](/packages/fieg-bayes)[niiknow/bayes

a machine learning lib

6954.1k](/packages/niiknow-bayes)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
