Home › Resources & tools › TensorFlow.js and linear regression

TensorFlow.js and linear regression

TensorFlow.js is a JavaScript machine learning library, part of the larger TensorFlow ecosystem used to build ML-powered applications. It packages a set of functionalities for training and deploying machine learning and deep learning models and runs both in a web browser and in the Node.js environment.

Simple linear regression is one of the most important types of data analysis which models the relationship between two variables. A special case of supervised learning, it is one of the simplest tasks that can be performed using TensorFlow.js.

A regular ML-based solution typically includes the following steps:

  1. Load and prepare the input data.
  2. Define the model architecture.
  3. Compile and training the model.
  4. Use the model to make predictions.

In a TensorFlow.js-based application, those steps correspond to the following sections of the code:

const { inputs, labels } = await getData()
const model = createModel()
model.compile(...)
await model.fit(inputs, labels, ...)
model.predict(...)

In the case of simple linear regression, the model architecture can be defined as follows:

const model = tf.sequential()
model.add(tf.layers.dense({ inputShape: [1], units: 1, useBias: true }))
model.add(tf.layers.dense({ units: 1, useBias: true }))

See also

"Hello, World!" Code Snippet Poster, JavaScript Programming Language
$14.99

A poster featuring the "Hello, World!" program in JavaScript programming language.

Hydrazine Molecule Poster, 2D Structure, English-Labeled
$19.99

A poster featuring the 2D structure of the hydrazine molecule.

рыболов Morphemic Analysis Poster
$14.99

A poster featuring the morphemic analysis of the Russian word рыболов.

Primates Evolutionary Tree Poster
$15.99

A poster featuring the phylogenetic tree of primates.

seq2seq Trainer

Train sequence-to-sequence models online.

A technical introduction to OpenAI's GPT-3 language model

An overview of the groundbreaking GPT-3 language model created by OpenAI.

SVMs in practice

A primer on support vector machines (SVMs) and their applications.

A beginner's guide to graph embeddings

Understanding what graph embeddings are and why they are important for graph analytics.

Loading npm dependencies from multiple registries

How to add npm dependencies from multiple package registries?

All prices listed are in United States Dollars (USD). Visual representations of products are intended for illustrative purposes. Actual products may exhibit variations in color, texture, or other characteristics inherent to the manufacturing process. The products' design and underlying technology are protected by applicable intellectual property laws. Unauthorized reproduction or distribution is prohibited.