// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Defining an array x
const Array_x = [
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1],
];
// Defining an array y
const Array_y = [1, 1, 1, 1];
// Defining dataset of x
const Dataset_x = tf.data.array(Array_x);
// Defining dataset of y
const Dataset_y = tf.data.array(Array_y);
// Defining dataset of xy using zip method
const Dataset_xy = tf.data.zip({xs: Dataset_x, ys: Dataset_y})
.batch(5)
.shuffle(3);
// Training Model
const gfg = tf.sequential();
// Adding layer to model
const layer = tf.layers.dense({units:1,
inputShape : [8]});
gfg.add(layer);
// Compiling our model
const config = {optimizer:'sgd',
loss:'meanSquaredError'};
gfg.compile(config);
// Calling evaluateDataset() method
const res = await gfg.evaluateDataset(Dataset_xy,
tf.ones([7, 10]), tf.ones([7, 1]), {
batchSize: 5,
});
// Printing output
res.print();