PHP code example of luminsports / linear-regression

1. Go to this page and download the library: Download luminsports/linear-regression library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

luminsports / linear-regression example snippets


use LuminSports\LinearRegression\LeastSquares;

$targets = [1, 2, 3, 4];
$observations = [2.1, 4.0, 6.2, 7.9];

$regression = new LeastSquares($targets, $observations);

$slope = $regression->getSlope();
$intercept = $regression->getIntercept();
$rSquared = $regression->getRSquared();

$predictedObservation = $regression->predictY(5);
$predictedTarget = $regression->predictX(10);

$residuals = $regression->getDifferencesFromRegressionLine();
$cumulativeResiduals = $regression->getCumulativeSumOfDifferencesFromRegressionLine();
$linePoints = $regression->getRegressionLinePoints();

$regression = new LeastSquares($targets, $observations, precision: 12);
$regression->setPrecision(10);