2016-04-07 20:36:02 +00:00
|
|
|
<?php
|
|
|
|
|
2016-11-20 21:53:17 +00:00
|
|
|
declare(strict_types=1);
|
2016-04-07 20:36:02 +00:00
|
|
|
|
2018-01-06 12:09:33 +00:00
|
|
|
namespace Phpml\Tests\Dataset;
|
2016-04-07 20:36:02 +00:00
|
|
|
|
|
|
|
use Phpml\Dataset\ArrayDataset;
|
2017-11-28 07:00:13 +00:00
|
|
|
use Phpml\Exception\InvalidArgumentException;
|
2017-02-03 11:58:25 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-04-07 20:36:02 +00:00
|
|
|
|
2017-02-03 11:58:25 +00:00
|
|
|
class ArrayDatasetTest extends TestCase
|
2016-04-07 20:36:02 +00:00
|
|
|
{
|
2017-11-14 20:21:23 +00:00
|
|
|
public function testThrowExceptionOnInvalidArgumentsSize(): void
|
2016-04-07 20:36:02 +00:00
|
|
|
{
|
2017-11-28 07:00:13 +00:00
|
|
|
$this->expectException(InvalidArgumentException::class);
|
2016-04-07 20:36:02 +00:00
|
|
|
new ArrayDataset([0, 1], [0]);
|
|
|
|
}
|
|
|
|
|
2017-11-14 20:21:23 +00:00
|
|
|
public function testArrayDataset(): void
|
2016-04-07 20:36:02 +00:00
|
|
|
{
|
|
|
|
$dataset = new ArrayDataset(
|
|
|
|
$samples = [[1], [2], [3], [4]],
|
|
|
|
$labels = ['a', 'a', 'b', 'b']
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals($samples, $dataset->getSamples());
|
2016-06-16 21:56:15 +00:00
|
|
|
$this->assertEquals($labels, $dataset->getTargets());
|
2016-04-07 20:36:02 +00:00
|
|
|
}
|
2018-03-03 15:04:21 +00: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]);
|
|
|
|
|
|
|
|
$this->assertEquals([[2, 4], [3, 5], [4, 6], [5, 7]], $dataset->getSamples());
|
|
|
|
}
|
2016-04-07 20:36:02 +00:00
|
|
|
}
|