Registry / data / regression

regression

JSON →
library0.1jsnpmunverified

regression-js is a JavaScript module that provides a collection of linear least-squares fitting methods for simple data analysis. It offers capabilities for linear, exponential, logarithmic, power, and polynomial regression. The current stable version is 2.0.1, last published over 8 years ago, suggesting a mature but potentially unmaintained codebase, though it remains widely used. It is a lightweight, pure JavaScript solution that runs both in Node.js and modern browsers. Unlike some broader machine learning libraries, regression-js focuses specifically on classical least-squares curve fitting, providing a straightforward API for common trend analysis tasks without external dependencies.

npm install regression
INSTALL
IMPORT
SIG · REGRESSION
R
regression
datajavascriptv0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

regression
import regression from 'regression';
const regression = require('regression');
The library primarily uses a default export pattern. The 'regression' package provides a single object containing all regression methods. While CommonJS `require` works in Node.js environments, ESM `import` is the recommended standard for modern JavaScript.
regression.linear
import regression from 'regression'; const result = regression.linear(data);
import { linear } from 'regression'; // Incorrect - linear is a method of the default export const result = linear(data);
Individual regression methods like `linear` are properties of the default `regression` object, not named exports themselves. They must be accessed via the imported default object.
regression.polynomial
import regression from 'regression'; const result = regression.polynomial(data, { order: 3 });
const result = regression('polynomial', data, 3); // Old API from earlier versions
Since version 2.0.0, the API for calling regression methods changed from a single `regression(type, data, options)` function to directly calling `regression.type(data, options)`. Also note the `order` option for polynomial regression.

Demonstrates how to import the `regression` library, perform linear and polynomial regression on sample data, and predict values using the generated models.

import regression from 'regression'; // Sample data: [[x1, y1], [x2, y2], ...] const data = [ [0, 1], [32, 67], [12, 79], [5, 10], [15, 30], [25, 50], [40, 85], [50, 100] ]; // Perform linear regression const linearResult = regression.linear(data); console.log('Linear Regression Result:'); console.log(' Equation:', linearResult.equation); // [m, c] console.log(' String:', linearResult.string); console.log(' R-squared (R²):', linearResult.r2); console.log(' Prediction for x=45:', linearResult.predict(45)[1]); // Perform polynomial regression with order 2 const polynomialResult = regression.polynomial(data, { order: 2 }); console.log('\nPolynomial Regression (Order 2) Result:'); console.log(' Equation:', polynomialResult.equation); // [a_n, ..., a_1, a_0] console.log(' String:', polynomialResult.string); console.log(' R-squared (R²):', polynomialResult.r2); console.log(' Prediction for x=45:', polynomialResult.predict(45)[1]);
Debug
Known issues
breakingVersion 2.0.0 introduced significant API changes, moving from a single `regression(type, data, options)` function to direct method calls like `regression.linear(data, options)`. Old call patterns will no longer work.
fix
Update usage to call specific regression methods directly on the imported `regression` object, e.g., `regression.linear(data)` instead of `regression('linear', data)`.
affects: >=2.0.0
gotchaInput data must be an array of `[x, y]` pairs (e.g., `[[0, 1], [32, 67]]`). Providing data in other formats (e.g., objects like `{ x: 0, y: 1 }` or separate X and Y arrays) will lead to errors.
fix
Ensure all input data is formatted as `Array<[number, number]>`.
affects: >=1.0.0
gotchaThe `precision` option (defaulting to 2 significant figures) rounds the output equation coefficients. If high precision is required for intermediate calculations, be aware of this rounding or set `precision` to a higher value or `null`.
fix
Set the `precision` option in the configuration object to a higher number or `null` for full precision, e.g., `{ precision: 10 }` or `{ precision: null }`.
affects: >=1.0.0
deprecatedThe `lastvalue` and `linearThroughOrigin` methods were removed in version 2.0.0. Linear regression through the origin is now handled by the standard `linear` model.
fix
For linear regression through the origin, use `regression.linear()` and interpret the `yIntercept` as zero if that is your model assumption. The `lastvalue` functionality is no longer available directly.
affects: >=2.0.0
gotchaThe package's last publish was over 8 years ago. While stable, this indicates that the library is in maintenance mode and unlikely to receive new features, active bug fixes, or updates for modern JavaScript language features or security concerns.
fix
Consider its long-term viability for new projects. For active development, assess if an actively maintained alternative might be more suitable, or be prepared to fork and maintain if specific updates are needed.
affects: *
Errors
Common errors & fixes
TypeError: regression.linear is not a function
Attempting to call a method on `regression` when it was imported incorrectly, or the `regression` object itself is undefined due to a CJS/ESM mixup.
fix
Ensure you are using `import regression from 'regression';` for ESM contexts, or `const regression = require('regression');` for CommonJS. If using `regression('linear', data)`, update to `regression.linear(data)` as the old API was removed in v2.0.0.
TypeError: data is not an array
The `data` argument passed to any regression method is not in the expected `[[x1, y1], [x2, y2], ...]` format.
fix
Verify that your input data is an array of arrays, where each inner array contains exactly two numbers representing an [x, y] coordinate. E.g., `[[1, 2], [3, 4], [5, 6]]`.
TypeError: Cannot read properties of undefined (reading 'equation')
This usually occurs when trying to access properties like `equation`, `string`, or `r2` from the result of a regression call that failed or returned an unexpected value (e.g., if `data` was malformed and the function returned `undefined`).
fix
Before accessing properties, check if the `result` object is valid and contains the expected properties. Ensure the input `data` format is correct and the regression function executed successfully.
Upgrade
Version history
0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
OpenAI (training)
1
Resources
regression — npm install regression · libregistry