npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

clementreiffers-linear-regression

v2.0.3

Published

calculation of a linear regression

Downloads

26

Readme

linear-regression

javascript npm npm GitHub CI

Simple linear regression made in JavaScript.

How to install

npm i clementreiffers-linear-regression or yarn add clementreiffers-linear-regression if you use yarn instead of npm.

How to use

Linear Regression

The lightest function

the lightest function is very usefull if you're interested in getting only the essential parameters

import { linearRegression, predict } from "clementreiffers-linear-regression";
// import { computeLightLinearRegression } from "clementreiffers-linear-regression";

const x = [1, 2, 3, 4];
const y = [1, 2, 3, 4];
const lr = linearRegression(x, y, true); // if you want values into an Object

// executed only if true in linearRegression Function, it gives the same result as above
// computeLightLinearRegression(x, y);  

const pred1 = predict([1, 2], lr);
const pred2 = predict(6, lr);

console.log(lr); // to show the object which represents the linear regression

by trying this example above, you will have :

{ parameters: { a: 1, b: 0 } }

The loudest function

it will compute all necessary calculations and put it into the same json.

import { linearRegression, predict } from "clementreiffers-linear-regression";
// import { computeLoudLinearRegression } from "clementreiffers-linear-regression";

const x = [1, 2, 3, 4];
const y = [1, 2, 3, 4];
const lr = linearRegression(x, y); // if you want values into an Object

// executed by default, it gives the same result as above
// computeLoudLinearRegression(x, y); 

const pred1 = predict([1, 2], lr);
const pred2 = predict(6, lr);

console.log(lr); // to show the object which represents the linear regression

by trying this example above, you will have :

{
  parameters: { a: 1, b: 0 },
  trainData: { x: [ 1, 2, 3, 4 ], y: [ 1, 2, 3, 4 ] },
  trainCurvePredict: [ 1, 2, 3, 4 ],
  statistics: { r2: 0.9999999999999996, cost: 0, pearson: 0.9999999999999998 }
}

score

the score represents the capacity to do a linear regression with the data given.

import { score } from "clementreiffers-linear-regression";

const x = [1, 2, 3, 4];
const y = [1, 2, 3, 4];

console.log(score(x, y));

by executing this code you will have :

0.9999999999999996

cost function

import { linearRegression, costFunction } from "clementreiffers-linear-regression";

const x = [1, 2, 3, 4];
const y = [1, 2, 3, 4];

const lr = linearRegression(x, y);
const pred = predict(lr, x);

const cost = costFunction(y, pred);
console.log(cost);

by executing this function you will have :

0

How it is calculated

this package use the Covariance and Variance to calculate the linear regression, see here : https://en.wikipedia.org/wiki/Linear_regression

Contacts

any idea to improve this package ?

  • email me to : [email protected]
  • do a git issue on github
  • contact me on linkedin : https://www.linkedin.com/in/cl%C3%A9ment-reiffers-bb8983185/

Links

See the source code on github

See the package on npm