Camspiers\StatisticalClassifier\Classifier\SVM::setThreshold PHP Method

setThreshold() public method

Set the threshold probability a classifier document must meet
public setThreshold ( float $threshold )
$threshold float float value between 0-1
    public function setThreshold($threshold)
    {
        if (is_numeric($threshold)) {
            $this->threshold = $threshold;
            $this->svm->setOptions(array(\SVM::OPT_PROBABILITY => true));
            if ($this->model->isPrepared()) {
                $this->model->setPrepared(false);
            }
        } else {
            throw new \InvalidArgumentException("Threshold must be a float value between 0-1");
        }
    }

Usage Example

<?php

require_once __DIR__ . '/../vendor/autoload.php';
// Using a plain data array source for simplicity
use Camspiers\StatisticalClassifier\DataSource\DataArray;
use Camspiers\StatisticalClassifier\Classifier\SVM;
$source = new DataArray();
$source->addDocument('pig', 'Pigs are great. Pink and cute!');
$source->addDocument('wolf', 'Wolves have teeth. They are gray.');
$c = new SVM($source);
$c->setThreshold(0.6);
var_dump($c->classify('0943jf904jf09j34fpj'));