A fork for my own purposes
the main differences are:
- (3.0.0)
- js is now typescript
- excluded all interpolations other than linear
- added
linearBigthat usesbig.jsfor everything- default is max precision
20
- default is max precision
- uses vite for bundling
TODO add tests for linearBig
TODO currently yarn build and yarn buildMini will clear the dist, so we do not build normal and minified in one go
regression-js is a JavaScript module containing a collection of linear least-squares fitting methods for simple data analysis.
This module works on node and in the browser. It is available as the 'regression' package on npm. It is also available on a CDN.
npm install --save regression
import regression from 'regression';
const result = regression.linear([[0, 1], [32, 67], [12, 79]]);
const gradient = result.equation[0];
const yIntercept = result.equation[1];Data is passed into the model as an array. A second parameter can be used to configure the model. The configuration parameter is optional. null values are ignored. The precision option will set the number of significant figures the output is rounded to.
Below are the default values for the configuration parameter.
{
order: 2,
precision: 2,
}equation: an array containing the coefficients of the equationstring: A string representation of the equationpoints: an array containing the predicted data in the domain of the inputr2: the coefficient of determination (R2)predict(x): This function will return the predicted value
Fits the input data to a straight line with the equation 
[m, c].
Fits the input data to a exponential curve with the equation 
[a, b].
Fits the input data to a logarithmic curve with the equation 
[a, b].
Fits the input data to a power law curve with the equation 
[a, b].
Fits the input data to a polynomial curve with the equation 
[an..., a1, a0]. The order can be configure with the order option.
const data = [[0,1],[32, 67] .... [12, 79]];
const result = regression.polynomial(data, { order: 3 });- Install the dependencies with
npm install - To build the assets in the
distdirectory, usenpm run build - You can run the tests with:
npm run test.