php-ml/tests/Dataset/ArrayDatasetTest.php

41 lines
1.0 KiB
PHP
Raw Normal View History

2016-04-07 22:36:02 +02:00
<?php
2016-11-20 22:53:17 +01:00
declare(strict_types=1);
2016-04-07 22:36:02 +02:00
namespace Phpml\Tests\Dataset;
2016-04-07 22:36:02 +02:00
use Phpml\Dataset\ArrayDataset;
use Phpml\Exception\InvalidArgumentException;
2017-02-03 12:58:25 +01:00
use PHPUnit\Framework\TestCase;
2016-04-07 22:36:02 +02:00
2017-02-03 12:58:25 +01:00
class ArrayDatasetTest extends TestCase
2016-04-07 22:36:02 +02:00
{
public function testThrowExceptionOnInvalidArgumentsSize(): void
2016-04-07 22:36:02 +02:00
{
$this->expectException(InvalidArgumentException::class);
2016-04-07 22:36:02 +02:00
new ArrayDataset([0, 1], [0]);
}
public function testArrayDataset(): void
2016-04-07 22:36:02 +02:00
{
$dataset = new ArrayDataset(
$samples = [[1], [2], [3], [4]],
$labels = ['a', 'a', 'b', 'b']
);
2018-10-28 07:44:52 +01:00
self::assertEquals($samples, $dataset->getSamples());
self::assertEquals($labels, $dataset->getTargets());
2016-04-07 22:36:02 +02:00
}
public function testRemoveColumns(): void
{
$dataset = new ArrayDataset(
[[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]],
['a', 'a', 'b', 'b']
);
$dataset->removeColumns([0, 2]);
2018-10-28 07:44:52 +01:00
self::assertEquals([[2, 4], [3, 5], [4, 6], [5, 7]], $dataset->getSamples());
}
2016-04-07 22:36:02 +02:00
}