dataset = new Unlabeled([ ['nice', 'furry', 'friendly'], ['mean', 'furry', 'loner'], ['nice', 'rough', 'friendly'], ['mean', 'rough', 'friendly'], ]); $this->transformer = new OneHotEncoder(); } /** * @test */ public function build() : void { $this->assertInstanceOf(OneHotEncoder::class, $this->transformer); $this->assertInstanceOf(Transformer::class, $this->transformer); $this->assertInstanceOf(Stateful::class, $this->transformer); } /** * @test */ public function fitTransform() : void { $this->transformer->fit($this->dataset); $this->assertTrue($this->transformer->fitted()); $categories = $this->transformer->categories(); $this->assertIsArray($categories); $this->assertCount(3, $categories); $this->assertContainsOnly('array', $categories); $this->dataset->apply($this->transformer); $this->assertEquals([ [1, 0, 1, 0, 1, 0], [0, 1, 1, 0, 0, 1], [1, 0, 0, 1, 1, 0], [0, 1, 0, 1, 1, 0], ], $this->dataset->samples()); } /** * @test */ public function transformUnfitted() : void { $this->expectException(RuntimeException::class); $samples = $this->dataset->samples(); $this->transformer->transform($samples); } }