generator = new Agglomerate([ 'red' => new Blob([255, 32, 0], 50.0), 'green' => new Blob([0, 128, 0], 10.0), 'blue' => new Blob([0, 32, 255], 30.0), ], [0.5, 0.2, 0.3]); $this->estimator = new Pipeline([ new PolynomialExpander(2), new ZScaleStandardizer(), ], new SoftmaxClassifier(), true); $this->metric = new Accuracy(); srand(self::RANDOM_SEED); } protected function assertPreConditions() : void { $this->assertFalse($this->estimator->trained()); } /** * @test */ public function build() : void { $this->assertInstanceOf(Pipeline::class, $this->estimator); $this->assertInstanceOf(Online::class, $this->estimator); $this->assertInstanceOf(Probabilistic::class, $this->estimator); $this->assertInstanceOf(Scoring::class, $this->estimator); $this->assertInstanceOf(Persistable::class, $this->estimator); $this->assertInstanceOf(Estimator::class, $this->estimator); } /** * @test */ public function type() : void { $this->assertEquals(EstimatorType::classifier(), $this->estimator->type()); } /** * @test */ public function compatibility() : void { $expected = [ DataType::continuous(), ]; $this->assertEquals($expected, $this->estimator->compatibility()); } /** * @test */ public function params() : void { $expected = [ 'transformers' => [ new PolynomialExpander(2), new ZScaleStandardizer(), ], 'estimator' => new SoftmaxClassifier(), 'elastic' => true, ]; $this->assertEquals($expected, $this->estimator->params()); } /** * @test */ public function trainPartialPredict() : void { $training = $this->generator->generate(self::TRAIN_SIZE); $testing = $this->generator->generate(self::TEST_SIZE); $folds = $training->stratifiedFold(3); $this->estimator->train($folds[0]); $this->estimator->partial($folds[1]); $this->estimator->partial($folds[2]); $this->assertTrue($this->estimator->trained()); $predictions = $this->estimator->predict($testing); $score = $this->metric->score($predictions, $testing->labels()); $this->assertGreaterThanOrEqual(self::MIN_SCORE, $score); } /** * @test */ public function predictUntrained() : void { $this->expectException(RuntimeException::class); $this->estimator->predict(Unlabeled::quick()); } }