mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-18 11:15:10 +00:00
39 lines
1001 B
PHP
39 lines
1001 B
PHP
|
<?php
|
||
|
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace tests\Classification\Ensemble;
|
||
|
|
||
|
use Phpml\Classification\Ensemble\RandomForest;
|
||
|
use Phpml\Classification\DecisionTree;
|
||
|
use Phpml\Classification\NaiveBayes;
|
||
|
use Phpml\Classification\KNearestNeighbors;
|
||
|
use Phpml\ModelManager;
|
||
|
use tests\Classification\Ensemble\BaggingTest;
|
||
|
|
||
|
class RandomForestTest extends BaggingTest
|
||
|
{
|
||
|
protected function getClassifier($numBaseClassifiers = 50)
|
||
|
{
|
||
|
$classifier = new RandomForest($numBaseClassifiers);
|
||
|
$classifier->setFeatureSubsetRatio('log');
|
||
|
return $classifier;
|
||
|
}
|
||
|
|
||
|
protected function getAvailableBaseClassifiers()
|
||
|
{
|
||
|
return [ DecisionTree::class => ['depth' => 5] ];
|
||
|
}
|
||
|
|
||
|
public function testOtherBaseClassifier()
|
||
|
{
|
||
|
try {
|
||
|
$classifier = new RandomForest();
|
||
|
$classifier->setClassifer(NaiveBayes::class);
|
||
|
$this->assertEquals(0, 1);
|
||
|
} catch (\Exception $ex) {
|
||
|
$this->assertEquals(1, 1);
|
||
|
}
|
||
|
}
|
||
|
}
|