コード例 #1
0
 /**
  * @throws RegressionException
  */
 public function testCalculate()
 {
     $linear = new LinearRegression();
     $linear->setSourceSequence($this->rows[0]);
     $linear->calculate();
     /** @var RegressionModel $regressionModel */
     $regressionModel = $linear->getRegressionModel();
     $this->assertEquals('y = 142.4x + -341.2', $regressionModel->getEquation());
     $this->assertEquals(1083, round($regressionModel->getResultSequence()[9][1]));
     $this->assertEquals(940, round($regressionModel->getResultSequence()[8][1]));
     $this->assertEquals(798, round($regressionModel->getResultSequence()[7][1]));
     $regressionModel = RegressionFactory::linear($this->rows[1]);
     $this->assertEquals('y = 0.3x + 12.3', $regressionModel->getEquation());
     $this->assertEquals(13, round($regressionModel->getResultSequence()[0][1]));
     $this->assertEquals(13, round($regressionModel->getResultSequence()[1][1]));
     $this->assertEquals(13, round($regressionModel->getResultSequence()[2][1]));
 }
コード例 #2
0
 /**
  * @throws RegressionException
  */
 public function testCalculate()
 {
     $linear = new PowerRegression();
     $linear->setSourceSequence($this->rows[0]);
     $linear->calculate();
     /** @var RegressionModel $regressionModel */
     $regressionModel = $linear->getRegressionModel();
     $this->assertEquals('y = 7.52 + x^2.18', $regressionModel->getEquation());
     $this->assertEquals(1126, round($regressionModel->getResultSequence()[9][1]));
     $this->assertEquals(895, round($regressionModel->getResultSequence()[8][1]));
     $this->assertEquals(693, round($regressionModel->getResultSequence()[7][1]));
     $regressionModel = RegressionFactory::power($this->rows[1]);
     $this->assertEquals('y = 11.69 + x^0.11', $regressionModel->getEquation());
     $this->assertEquals(12, round($regressionModel->getResultSequence()[0][1]));
     $this->assertEquals(13, round($regressionModel->getResultSequence()[1][1]));
     $this->assertEquals(13, round($regressionModel->getResultSequence()[2][1]));
 }
コード例 #3
0
 /**
  * @throws RegressionException
  */
 public function testCalculate()
 {
     $linear = new LogarithmicRegression();
     $linear->setSourceSequence($this->rows[0]);
     $linear->calculate();
     /** @var RegressionModel $regressionModel */
     $regressionModel = $linear->getRegressionModel();
     $this->assertEquals('y = -320.03 + 504.51ln(x)', $regressionModel->getEquation());
     $this->assertEquals(842, round($regressionModel->getResultSequence()[9][1]));
     $this->assertEquals(788, round($regressionModel->getResultSequence()[8][1]));
     $this->assertEquals(729, round($regressionModel->getResultSequence()[7][1]));
     $regressionModel = RegressionFactory::logarithmic($this->rows[1]);
     $this->assertEquals('y = 11.73 + 1.43ln(x)', $regressionModel->getEquation());
     $this->assertEquals(12, round($regressionModel->getResultSequence()[0][1]));
     $this->assertEquals(13, round($regressionModel->getResultSequence()[1][1]));
     $this->assertEquals(13, round($regressionModel->getResultSequence()[2][1]));
 }
コード例 #4
0
 /**
  * @throws RegressionException
  */
 public function testCalculate()
 {
     $linear = new ExponentialRegression();
     $linear->setSourceSequence($this->rows[0]);
     $linear->calculate();
     /** @var RegressionModel $regressionModel */
     $regressionModel = $linear->getRegressionModel();
     $this->assertEquals('y = 30.2+ e^(0.39x)', $regressionModel->getEquation());
     $this->assertEquals(1470, round($regressionModel->getResultSequence()[9][1]));
     $this->assertEquals(997, round($regressionModel->getResultSequence()[8][1]));
     $this->assertEquals(676, round($regressionModel->getResultSequence()[7][1]));
     $regressionModel = RegressionFactory::exponential($this->rows[1]);
     $this->assertEquals('y = 12.36+ e^(0.02x)', $regressionModel->getEquation());
     $this->assertEquals(13, round($regressionModel->getResultSequence()[0][1]));
     $this->assertEquals(13, round($regressionModel->getResultSequence()[1][1]));
     $this->assertEquals(13, round($regressionModel->getResultSequence()[2][1]));
 }
コード例 #5
0
ファイル: example.php プロジェクト: robotomize/regression-php
$regressionModel = RegressionFactory::linear($testData);
/**
 * Calculate Exponential regression call calculate()
 */
$exponential = new ExponentialRegression();
$exponential->setSourceSequence($testData);
$exponential->calculate();
/**
 * And with Fabric method
 */
$regressionModel = $exponential->getRegressionModel();
/**
 * Calculate logarithmic regression call calculate()
 */
$logarithmic = new LogarithmicRegression();
$logarithmic->setSourceSequence($testData);
$logarithmic->calculate();
/** @var RegressionModel $regressionModel */
$regressionModel = $logarithmic->getRegressionModel();
$regressionModel = RegressionFactory::logarithmic($testData);
/**
 * Calculate power regression call calculate()
 */
$powerReg = new PowerRegression();
$powerReg->setSourceSequence($testData);
$powerReg->calculate();
/** @var RegressionModel $regressionModel */
$regressionModel = $powerReg->getRegressionModel();
$regressionModel = RegressionFactory::power($testData);
var_dump($regressionModel);
//var_dump(RegressionFactory::Power($testData));