PHPackages                             alexandreelise/svm-for-php - 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. alexandreelise/svm-for-php

ActivePhp-ext[Utility &amp; Helpers](/categories/utility)

alexandreelise/svm-for-php
==========================

LibSVM is an efficient solver for SVM classification and regression problems. The svm extension wraps this in a PHP interface for easy use in PHP scripts

010C++

Since May 21Pushed 2w agoCompare

[ Source](https://github.com/alexandreelise/svm-for-php)[ Packagist](https://packagist.org/packages/alexandreelise/svm-for-php)[ RSS](/packages/alexandreelise-svm-for-php/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

WHY ?
=====

[](#why-)

This repo was created because the original repo seems stable and unresponsive to latest PR for example for PHP8.5 and potentially above This repo is an attempt to make the original php-svm project thrive, while trying to adapt it to modern features and functionality php offers. It has been renamed to prevent naming collisions. To be clear, it's not being hostile. I basically cannot afford to wait.

> BELOW THIS LINE IS THE ORIGINAL README:

INTRODUCTION
============

[](#introduction)

Available via PECL: Documentation at:

LibSVM is an efficient solver for SVM classification and regression problems. The svm extension wraps this in a PHP interface for easy use in PHP scripts. As of version 0.2.0 the extension requires PHP 7.0 or above. Older versions are compatible with PHP from 5.2 to 5.6.

INSTALLATION
============

[](#installation)

Libsvm itself is required. A bundled libsvm version is delivered as of version 0.2.0 and will be used when libsvm is not available on the target system. An external libsvm is usually available through some package management or can be compiled from source when fetched directly from the website.

On ubuntu and other debian based systems, you may be able to installed the `libsvm-dev` package:

```
apt-get install libsvm-dev

```

If installing from the [website](http://www.csie.ntu.edu.tw/~cjlin/libsvm) then some steps will need to be taken as the package does not install automatically:

```
wget http://www.csie.ntu.edu.tw/~cjlin/cgi-bin/libsvm.cgi?+http://www.csie.ntu.edu.tw/~cjlin/libsvm+tar.gz
tar xvzf libsvm-3.1.tar.gz
cd libsvm-3.1
make lib
cp libsvm.so.1 /usr/lib
ln -s libsvm.so.1 libsvm.so
ldconfig
ldconfig --print | grep libsvm

```

This last step should show libsvm is installed.

Once libsvm is installed, the extension can be installed in the usual way.

INSTALLING ON WINDOWS
=====================

[](#installing-on-windows)

A prebuilt win32 DLL is available from . The latest development snapshots are also fetcheable from AppVeyor artifacts.

The extension builds properly on Windows, if following the Windows step by step build process:

1. Put SVM source in pecl/svm in phpdev directory
2. Download latest libsvm, rename Makefile to Makefile.old and Makefile.win to Makefile - nmake
3. Copy libsvm.lib from libsvm windows directory, and into deps/libs
4. Copy svm.h into `includes/libsvm/`

```
buildconf
configure --disable-all --enable-cli --with-svm=shared
nmake

```

Note, that if the bundled libsvm is used, the instructions about the libsvm setup can be ommited. Otherwise, make sure the libsvm.dll file from the libsvm windows directory in the path when running the resulting lib.

USAGE
=====

[](#usage)

The basic process is to define parameters, supply training data to generate a model on, then make predictions based on the model. There are a default set of parameters that should get some results with most any input, so we'll start by looking at the data.

Data is supplied in either a file, a stream, or as an an array. If supplied in a file or a stream, it must contain one line per training example, which must be formatted as an integer class (usually 1 and -1) followed by a series of feature/value pairs, in increasing feature order. The features are integers, the values floats, usually scaled 0-1. For example:

```
-1 1:0.43 3:0.12 9284:0.2

```

In a document classification problem, say a spam checker, each line would represent a document. There would be two classes, -1 for spam, 1 for ham. Each feature would represent some word, and the value would represent that importance of that word to the document (perhaps the frequency count, with the total scaled to unit length). Features that were 0 (e.g. the word did not appear in the document at all) would simply not be included.

In array mode, the data must be passed as an array of arrays. Each sub-array must have the class as the first element, then key =&gt; value sets for the feature values pairs. E.g.

```
array(
	array(-1, 1 => 0.43, 3 => 0.12, 9284 => 0.2),
);

```

This data is passed to the SVM class's train function, which will return an SVM model is successful.

```
$svm = new SVM();
$model = $svm->train($data);

```

or, for example with a filename

```
$svm = new SVM();
$model = $svm->train("traindata.txt");

```

Once a model has been generated, it can be used to make predictions about previously unseen data. This can be passed as an array to the model's predict function, in the same format as before, but without the label. The response will be the class.

```
$data = array(1 => 0.43, 3 => 0.12, 9284 => 0.2);
$result = $model->predict($data);

```

In this case, $result would be -1.

Models can be saved and restored as required, using the save and load functions, which both take a file location.

```
$model->save('model.svm');

```

And to load:

```
$model = new SVMModel();
$model->load('model.svm');

```

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance63

Regular maintenance activity

Popularity7

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 61% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/d3cf4165e06984a34ac3a080b5fd7551382155ea9a49b5c3aef118bcb9358d5a?d=identicon)[alexandreelise](/maintainers/alexandreelise)

---

Top Contributors

[![ianbarber](https://avatars.githubusercontent.com/u/210006?v=4)](https://github.com/ianbarber "ianbarber (83 commits)")[![weltling](https://avatars.githubusercontent.com/u/22016?v=4)](https://github.com/weltling "weltling (43 commits)")[![alexandreelise](https://avatars.githubusercontent.com/u/51425450?v=4)](https://github.com/alexandreelise "alexandreelise (5 commits)")[![remicollet](https://avatars.githubusercontent.com/u/270445?v=4)](https://github.com/remicollet "remicollet (3 commits)")[![njam](https://avatars.githubusercontent.com/u/360800?v=4)](https://github.com/njam "njam (1 commits)")[![rlerdorf](https://avatars.githubusercontent.com/u/54641?v=4)](https://github.com/rlerdorf "rlerdorf (1 commits)")

### Embed Badge

![Health badge](/badges/alexandreelise-svm-for-php/health.svg)

```
[![Health](https://phpackages.com/badges/alexandreelise-svm-for-php/health.svg)](https://phpackages.com/packages/alexandreelise-svm-for-php)
```

###  Alternatives

[roots/allow-svg

WordPress plugin to enable SVG uploads

4137.4k](/packages/roots-allow-svg)

PHPackages © 2026

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