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 regressionVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to import the `regression` library, perform linear and polynomial regression on sample data, and predict values using the generated models.
Update usage to call specific regression methods directly on the imported `regression` object, e.g., `regression.linear(data)` instead of `regression('linear', data)`.Ensure all input data is formatted as `Array<[number, number]>`.
Set the `precision` option in the configuration object to a higher number or `null` for full precision, e.g., `{ precision: 10 }` or `{ precision: null }`.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.
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.
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.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]]`.
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.
No dependency data recorded yet.