ml-regression-simple-linear
TypeScript icon, indicating that this package has built-in type declarations

3.0.1 • Public • Published

regression-simple-linear

NPM version build status npm download codecov

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

/ml-regression-simple-linear/

    Package Sidebar

    Install

    npm i ml-regression-simple-linear

    Weekly Downloads

    136,713

    Version

    3.0.1

    License

    MIT

    Unpacked Size

    30.1 kB

    Total Files

    13

    Last publish

    Collaborators

    • stropitek
    • targos
    • lpatiny
    • mljs-bot
    • maasencioh
    • jeffersonh44
    • andcastillo