public function testComplexCase() { $r = new LinearRegression(Dataset::fromArray([0.5, 1, 4, -1])); $this->assertSame(-0.15, $r->slope()); $this->assertSame(1.35, $r->intercept()); $this->assertSame(0.0, $r(9)); }
public function get($id) { $this->queryDataset->bindValue(':id', intval($id), PDO::PARAM_INT); $this->queryDataset->execute(); $datasets = $this->queryDataset->fetchAll(PDO::FETCH_ASSOC); $numDatasets = count($datasets); $this->queryDataset->closeCursor(); if ($numDatasets < 1) { throw new Exception(self::$EXCEPTION_NO_DATASET); } else { if ($numDatasets > 1) { throw new Exception(self::$EXCEPTION_MULT_DATASETS); } else { $dataset = $datasets[0]; $dataset['iml'] = $this->_dbStringToArray($dataset['iml']); return Dataset::fromArray($dataset); } } }
public function testFromArray() { $dataset = Dataset::fromArray([1, 2, 3, [3.2, 4]]); $this->assertInstanceOf(Dataset::class, $dataset); $this->assertSame([[0.0, 1.0], [1.0, 2.0], [2.0, 3.0], [3.2, 4.0]], $dataset->toArray()); }