NodeJsTensorFlow.js for Machine Learning

TensorFlow.js lets you run machine learning models directly in Node.js. You can train models or load pre-trained ones for tasks like image classification, speech recognition, or predictive analytics.

npm install @tensorflow/tfjs

const tf = require('@tensorflow/tfjs');

const model = tf.sequential();
model.add(tf.layers.dense({ units: 1, inputShape: [1] }));
model.compile({ optimizer: 'sgd', loss: 'meanSquaredError' });

const xs = tf.tensor2d([1, 2, 3, 4], [4, 1]);
const ys = tf.tensor2d([1, 3, 5, 7], [4, 1]);

model.fit(xs, ys).then(() => {
  model.predict(tf.tensor2d([5], [1, 1])).print();
});