PHPackages                             camspiers/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. camspiers/statistical-classifier

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

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

0.8.0(12y ago)17337.0k24[5 issues](https://github.com/camspiers/statistical-classifier/issues)[1 PRs](https://github.com/camspiers/statistical-classifier/pulls)1MITPHPPHP &gt;=5.3.3

Since Mar 14Pushed 9y ago20 watchersCompare

[ Source](https://github.com/camspiers/statistical-classifier)[ Packagist](https://packagist.org/packages/camspiers/statistical-classifier)[ Docs](http://php-classifier.com/)[ RSS](/packages/camspiers-statistical-classifier/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (5)Versions (22)Used By (1)

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

37

—

LowBetter than 81% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97% 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 ~15 days

Recently: every ~28 days

Total

21

Last Release

4562d 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/51294?v=4)[Cam Spiers](/maintainers/camspiers)[@camspiers](https://github.com/camspiers)

---

Top Contributors

[![camspiers](https://avatars.githubusercontent.com/u/51294?v=4)](https://github.com/camspiers "camspiers (131 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/camspiers-statistical-classifier/health.svg)

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

###  Alternatives

[symfony/ux-cropperjs

Cropper.js integration for Symfony

19346.6k3](/packages/symfony-ux-cropperjs)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M574](/packages/shopware-core)[2lenet/crudit-bundle

The easy like Crud'it Bundle.

1616.4k14](/packages/2lenet-crudit-bundle)[symfony/ux-toggle-password

Toggle visibility of password inputs for Symfony Forms

27600.4k5](/packages/symfony-ux-toggle-password)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9421.6k61](/packages/open-dxp-opendxp)

PHPackages © 2026

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