Skip to content
Simple Linear Regression
JavaScript
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src test: improve test coverage Jun 19, 2019
.babelrc chore: update dependencies Apr 30, 2019
.eslintrc.yml
.gitignore
.npmrc chore: update dependencies Apr 30, 2019
.travis.yml chore: update dependencies Apr 30, 2019
History.md 2.0.2 Jun 19, 2019
LICENSE feat: implement simple linear regression Apr 28, 2017
README.md fix github name [ci skip] Apr 28, 2017
package.json 2.0.2 Jun 19, 2019
regression-simple-linear.d.ts fix: correct TS definitions Jun 19, 2019
rollup.config.js chore: update dependencies Apr 30, 2019

README.md

regression-simple-linear

NPM version build status npm download

Simple Linear Regression.

Installation

$ npm install --save ml-regression-simple-linear

Usage

import SimpleLinearRegression from 'ml-regression-simple-linear';

const x = [0.5, 1, 1.5, 2, 2.5];
const y = [0, 1, 2, 3, 4];

const regression = new SimpleLinearRegression(x, y);

regression.slope // 2
regression.intercept // -1
regression.coefficients // [-1, 2]

regression.predict(3); // 5
regression.computeX(3.5); // 2.25

regression.toString(); // 'f(x) = 2 * x - 1'

regression.score(x, y);
// { r: 1, r2: 1, chi2: 0, rmsd: 0 }

const json = regression.toJSON();
// { name: 'simpleLinearRegression', slope: 2, intercept: -1 }
const loaded = SimpleLinearRegression.load(json);
loaded.predict(5) // 9

License

MIT

You can’t perform that action at this time.