mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-29 00:06:31 +00:00
add test with dataset example
This commit is contained in:
parent
d19490d62a
commit
23eff0044a
@ -4,7 +4,11 @@ declare (strict_types = 1);
|
|||||||
|
|
||||||
namespace tests\Phpml\Metric;
|
namespace tests\Phpml\Metric;
|
||||||
|
|
||||||
|
use Phpml\Classification\SVC;
|
||||||
|
use Phpml\CrossValidation\RandomSplit;
|
||||||
|
use Phpml\Dataset\Demo\Iris;
|
||||||
use Phpml\Metric\Accuracy;
|
use Phpml\Metric\Accuracy;
|
||||||
|
use Phpml\SupportVectorMachine\Kernel;
|
||||||
|
|
||||||
class AccuracyTest extends \PHPUnit_Framework_TestCase
|
class AccuracyTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
@ -34,4 +38,19 @@ class AccuracyTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->assertEquals(3, Accuracy::score($actualLabels, $predictedLabels, false));
|
$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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user