PHPackages                             luminsports/linear-regression - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. luminsports/linear-regression

ActiveLibrary

luminsports/linear-regression
=============================

Linear regression

1.3.1(1mo ago)215MITPHPPHP ^8.1CI passing

Since Aug 18Pushed 1mo agoCompare

[ Source](https://github.com/luminsports/php-linear-regression)[ Packagist](https://packagist.org/packages/luminsports/linear-regression)[ RSS](/packages/luminsports-linear-regression/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (8)Versions (9)Used By (0)

Least Squares Linear Regression class
=====================================

[](#least-squares-linear-regression-class)

[![Code Style](https://github.com/luminsports/php-linear-regression/actions/workflows/php-cs-fixer.yml/badge.svg?branch=main)](https://github.com/luminsports/php-linear-regression/actions/workflows/php-cs-fixer.yml)[![Tests](https://github.com/luminsports/php-linear-regression/actions/workflows/run-tests.yml/badge.svg?branch=main)](https://github.com/luminsports/php-linear-regression/actions/workflows/run-tests.yml)

A Linear regression class that uses the least squares method to approximate a straight line to a data set. Forked from [davebarnwell/ml-regression-least-squares](https://github.com/davebarnwell/ml-regression-least-squares), this version uses new PHP 8.1 syntax, and BCMath for high precision.

`composer install luminsports/linear-regression`

Usage:

```
$x = [...]; // target values
$y = [...]; // observation values

$linearRegression = new \LuminSports\LinearRegression\LeastSquares($x, $y);

$slope = $linearRegression->getSlope();
$yIntercept = $linearRegression->getIntercept();

// return array of differences of y values from the regression line
$differences = $linearRegression->getDifferencesFromRegressionLine();

// return array of cumulative sum of the differences of y values from the regression line
$cumulativeSum = $linearRegression->getCumulativeSumOfDifferencesFromRegressionLine();

// return array of Point objects giving the x,y values of the regression line
// for current data
$regressionLine = $linearRegression->getRegressionLinePoints();

$regressionLine[0]->getX();
$regressionLine[0]->getY();

$predictedX = $linearRegression->predictX($anObservationValue);

$predictedY = $linearRegression->predictY($aTargetValue);

$rSquared = $linearRegression->getRSquared(); // Regression fit; 1 = perfect fit 0 = no fit

```

###  Health Score

45

—

FairBetter than 92% of packages

Maintenance92

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 57.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~220 days

Recently: every ~330 days

Total

7

Last Release

40d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0e55216f06906e0bdee2b78e0b2c0c9d5009a4bbab212341d04e3584ba8d864c?d=identicon)[ryzr](/maintainers/ryzr)

---

Top Contributors

[![davebarnwell](https://avatars.githubusercontent.com/u/97731?v=4)](https://github.com/davebarnwell "davebarnwell (20 commits)")[![ryzr](https://avatars.githubusercontent.com/u/9389421?v=4)](https://github.com/ryzr "ryzr (14 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

php

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/luminsports-linear-regression/health.svg)

```
[![Health](https://phpackages.com/badges/luminsports-linear-regression/health.svg)](https://phpackages.com/packages/luminsports-linear-regression)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.6k509.9M17.0k](/packages/laravel-framework)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.3k](/packages/illuminate-database)[brick/money

Money and currency library

1.9k37.9M102](/packages/brick-money)[bavix/laravel-wallet

It's easy to work with a virtual wallet.

1.3k1.1M11](/packages/bavix-laravel-wallet)[illuminate/validation

The Illuminate Validation package.

18936.7M1.4k](/packages/illuminate-validation)[flow-php/etl

PHP ETL - Extract Transform Load - Abstraction

374468.4k51](/packages/flow-php-etl)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
