assertEquals($transformers, $pipeline->getTransformers()); $this->assertEquals($estimator, $pipeline->getEstimator()); } public function testPipelineEstimatorSetter(): void { $pipeline = new Pipeline([new TfIdfTransformer()], new SVC()); $estimator = new SVR(); $pipeline->setEstimator($estimator); $this->assertEquals($estimator, $pipeline->getEstimator()); } public function testPipelineWorkflow(): void { $transformers = [ new Imputer(null, new MostFrequentStrategy()), new Normalizer(), ]; $estimator = new SVC(); $samples = [ [1, -1, 2], [2, 0, null], [null, 1, -1], ]; $targets = [ 4, 1, 4, ]; $pipeline = new Pipeline($transformers, $estimator); $pipeline->train($samples, $targets); $predicted = $pipeline->predict([[0, 0, 0]]); $this->assertEquals(4, $predicted[0]); } public function testPipelineTransformers(): void { $transformers = [ new TokenCountVectorizer(new WordTokenizer()), new TfIdfTransformer() ]; $estimator = new SVC(); $samples = [ 'Hello Paul', 'Hello Martin', 'Goodbye Tom', 'Hello John', 'Goodbye Alex', 'Bye Tony', ]; $targets = [ 'greetings', 'greetings', 'farewell', 'greetings', 'farewell', 'farewell', ]; $pipeline = new Pipeline($transformers, $estimator); $pipeline->train($samples, $targets); $expected = ['greetings', 'farewell']; $predicted = $pipeline->predict(['Hello Max', 'Goodbye Mark']); $this->assertEquals($expected, $predicted); } }