• Stars
    star
    175
  • Rank 218,059 (Top 5 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 12 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

PHP Classifier

Build Status Latest Stable Version

PHP Classifier uses semantic versioning, it is currently at major version 0, so the public API should not be considered stable.

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

  • 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

$ composer require camspiers/statistical-classifier

SVM Support

For SVM Support both libsvm and php-svm are required. For installation intructions refer to php-svm.

Usage

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

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 requires maximebf/CacheCache which can be installed via packagist. Additional caching systems can be easily integrated.

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

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

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

More Repositories

1

lens.vim

A Vim Automatic Window Resizing Plugin
Vim Script
467
star
2

snap

A fast finder system for neovim.
Fennel
421
star
3

dotfiles

Dotfiles (macOS, stow, brew, yabai, nvim, kitty, tmux)
Clojure
206
star
4

animate.vim

A Vim Window Animation Library
Vim Script
202
star
5

reactjs-php-render

React rendering from PHP
PHP
45
star
6

tmuxinator-fzf-start

Uses fzf to provide a selection list for starting tmuxinator projects
Shell
40
star
7

Bayes

A Baysian calculator and visualization tool implemented in HTML, CSS, and JavaScript
JavaScript
23
star
8

json-pretty

Provides support for json pretty printing in php 5.3
PHP
23
star
9

silverstripe-twig

Allows the use of twig as a template engine in SilverStripe
PHP
20
star
10

php-fp

Functional Programming Helpers
PHP
17
star
11

porter-stemmer

Porter Stemmer created by Richard Heyes
PHP
14
star
12

silverstripe-loggerbridge

Provides a bridge between PSR-3 loggers (like monolog) and SilverStripe
PHP
13
star
13

silverstripe-slowlog

Logs slow SilverStripe requests
PHP
10
star
14

pthreads-pool

A basic and experimental implementation of a thread pool for pthreads
PHP
8
star
15

silverstripe-honeypot

SilverStripe honey pot capture
PHP
7
star
16

luarocks

Easily install luarocks with lazy.nvim
Lua
4
star
17

silverstripe-haml

Allows the use of haml in SilverStripe
PHP
4
star
18

elm-redchaser

A basic game written in Elm
Elm
4
star
19

readydocker

A macOS tool for starting then waiting for Docker.app to be ready
Shell
4
star
20

silverstripe-classifierbridge

SilverStripe tools for using statistical classifier
PHP
3
star
21

silverstripe-fixturegenerator

Allows the generation of SilverStripe unit test fixtures from existing DataObjects either programatically created or from the database
PHP
3
star
22

silverstripe-composer-autoload

Allows use of composer in SilverStripe projects
PHP
2
star
23

silverstripe-markdown

Markdown in SilverStripe
PHP
2
star
24

php-trait-convert

Limited ability to convert php classes that use traits
PHP
1
star
25

silverstripe-csp-logging

Logs CSP violations through a logger
PHP
1
star
26

shared-dependency-injection

PHP
1
star
27

closureaccess

Brings JavaScript-like functionality to your objects
PHP
1
star
28

php-lib-create

Creates a PHP composer library with useful defaults (github repo, phpunit, travis, namespace, php-cs-fixer, README)
PHP
1
star