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 🙏

© 2026 – Pkg Stats / Ryan Hefner

linear-regression-tfjs

v1.0.2

Published

Simple and complex linear regressions with javascript made easy

Readme

LINEAR REGRESSION JS

Library for linear regression in Javascript. You can run it on your backend in Node!

INSTALL

npm install linear-regression-tfjs

how to use linear regression

const LinearRegressionJs = require('linear-regression-tfjs')

or

import LinearRegressionJs from 'linear-regression-tfjs'
let linearRegressionJs = new LinearRegressionJs();

Now everything is ready for you to start making two predictions with your library!

METHODS

linearRegression

This asynchronous method returns a simple linear regression output. This method accepts two numeric arrays as an argument.

async linearRegression(x = [], y = [])  

Let's view an example:

    let predict = await linearRegressionJs.linearRegression([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 20, 30, 40, 50, 60])

Note that the first argument has a larger dimension. So we want to have the prediction of the indices that don't exist in y. So we see that y is a function of x

The return of this function will be...

{
  one: [
    1, 2, 3, 4,  5,
    6, 7, 8, 9, 10
  ],
  predict: [
    10, 20, 30, 40,  50,
    60, 70, 80, 90, 100
  ]
}

Cool!!!

asyncompileAndTrain

Training and saving a model!

This method becomes more interesting, since with it we can train a model and leave it saved.. so that it can be used in the future on several occasions.

async asyncompileAndTrain(x, y, epochs, prefix)

Let's analyze the arguments.

  • X = It is a one-dimensional array of numbers.
  • Y = is a tensor and must be reported as one.
  • epochs = Training period of our model (The callback is shown in the console so you can check the best number of epochs for your model.)
  • prefix = It is the directory where you want to save your model. By default, tensorflow will always save your model as "model.json" plus a binary.

Let's see an implementation example:

 let dir = `${__dirname}/models`
 let predict = await linearRegressionJs.asyncompileAndTrain([1, 2, 3, 4, 5], [[10], [20], [30], [40], [50]], 1500, dir)

It is important to note that you must use __dirname to get your application's directory. And remember to create the directories you want to store your model. In the case of the examples, we created the "models" directory and passed it in dir.

The return of this function will be...

{ message: 'SUCCESS' }

After this process, you will see your model within the specified directory. Now we are ready to use it.

linearRegressionNode

This method will perform a prediction based on a pre-trained model. (as done in the previous method)

 async linearRegressionNode(model, y)

Let's analyze the arguments.

  • model = The directory where we have a pre-trained model.
  • y = Numeric array from which we want to extract a prediction
 let dir = `${__dirname}/models`
 let predict = await linearRegressionJs.linearRegressionNode(dir,[6, 7, 8, 9,10,11])
 console.log(predict)

If you noticed. In the asyncompileAndTrain function we trained the multiples of 10 from 0 to 5. Now we want our model to tell us what the predictions would be for 6 to 11.

The return of this call will be:

{
  vector: [ 6, 7, 8, 9, 10, 11 ],
  prefict: [ 60, 70, 80, 90, 100, 110 ]
}

final thoughts

You can use this library in several ways. It can predict coin prices, population numbers, player actions and many others. If you want to contribute to the library with improvements and functions, feel free and you will be very welcome.