mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-16 02:07:08 +00:00
db82afa263
* Update to phpunit 8 * Require at least PHP 7.2
30 lines
1.3 KiB
PHP
30 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Phpml\Tests\FeatureSelection\ScoringFunction;
|
|
|
|
use Phpml\FeatureSelection\ScoringFunction\UnivariateLinearRegression;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class UnivariateLinearRegressionTest extends TestCase
|
|
{
|
|
public function testRegressionScore(): void
|
|
{
|
|
$samples = [[73676, 1996], [77006, 1998], [10565, 2000], [146088, 1995], [15000, 2001], [65940, 2000], [9300, 2000], [93739, 1996], [153260, 1994], [17764, 2002], [57000, 1998], [15000, 2000]];
|
|
$targets = [2000, 2750, 15500, 960, 4400, 8800, 7100, 2550, 1025, 5900, 4600, 4400];
|
|
|
|
$function = new UnivariateLinearRegression();
|
|
self::assertEqualsWithDelta([6.97286, 6.48558], $function->score($samples, $targets), 0.0001);
|
|
}
|
|
|
|
public function testRegressionScoreWithoutCenter(): void
|
|
{
|
|
$samples = [[73676, 1996], [77006, 1998], [10565, 2000], [146088, 1995], [15000, 2001], [65940, 2000], [9300, 2000], [93739, 1996], [153260, 1994], [17764, 2002], [57000, 1998], [15000, 2000]];
|
|
$targets = [2000, 2750, 15500, 960, 4400, 8800, 7100, 2550, 1025, 5900, 4600, 4400];
|
|
|
|
$function = new UnivariateLinearRegression(false);
|
|
self::assertEqualsWithDelta([1.74450, 18.08347], $function->score($samples, $targets), 0.0001);
|
|
}
|
|
}
|