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)17237.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 1mo ago

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 83% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity41

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

4508d ago

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

0.4.0PHP &gt;=5.3.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/91d02ba78b01d0432821f6195f11d6b95aa8da31f02f8aaea7a2e7215662061a?d=identicon)[camspiers](/maintainers/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

[rubix/ml

A high-level machine learning and deep learning library for the PHP language.

2.2k1.4M28](/packages/rubix-ml)[fieg/bayes

Implementation of Naive Bayes Classifier algorithm in PHP.

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

a machine learning lib

6950.0k](/packages/niiknow-bayes)[php-soap/ext-soap-engine

An ext-soap engine implementation

443.2M7](/packages/php-soap-ext-soap-engine)[symfony/ux-toggle-password

Toggle visibility of password inputs for Symfony Forms

26508.0k5](/packages/symfony-ux-toggle-password)[netgen/layouts-core

Netgen Layouts enables you to build and manage complex web pages in a simpler way and with less coding. This is the core of Netgen Layouts, its heart and soul.

3689.4k10](/packages/netgen-layouts-core)

PHPackages © 2026

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