add test with dataset example

This commit is contained in:
Arkadiusz Kondas 2016-05-31 20:01:54 +02:00
parent d19490d62a
commit 23eff0044a

View File

@ -4,7 +4,11 @@ declare (strict_types = 1);
namespace tests\Phpml\Metric;
use Phpml\Classification\SVC;
use Phpml\CrossValidation\RandomSplit;
use Phpml\Dataset\Demo\Iris;
use Phpml\Metric\Accuracy;
use Phpml\SupportVectorMachine\Kernel;
class AccuracyTest extends \PHPUnit_Framework_TestCase
{
@ -34,4 +38,19 @@ class AccuracyTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(3, Accuracy::score($actualLabels, $predictedLabels, false));
}
public function testAccuracyOnDemoDataset()
{
$dataset = new RandomSplit(new Iris(), 0.5, 123);
$classifier = new SVC(Kernel::RBF);
$classifier->train($dataset->getTrainSamples(), $dataset->getTrainLabels());
$predicted = $classifier->predict($dataset->getTestSamples());
$accuracy = Accuracy::score($dataset->getTestLabels(), $predicted);
$this->assertEquals(0.959, $accuracy, '', 0.01);
}
}