import * as tf from "@tensorflow/tfjs";
const x = tf.tensor([5, 6, 7, 8, 9, 2], [3, 2]);
const x1 = tf.tensor([8, 7, 6, 5, 2, 9], [3, 2]);
const y = tf.tensor([1, 3, 3, 4, 4, 6, 6, 8, 9], [3, 3]);
const y1 = tf.tensor([2, 2, 2, 1, 5, 5, 2, 3, 8], [3, 3]);
const model = tf.sequential();
model.add(
tf.layers.dense({
units: 3,
inputShape: [2],
})
);
model.compile({ loss: "meanSquaredError",
optimizer: "sgd", metrics: ["acc"] });
const history = await model.fit(x, y, {
epochs: 10,
validationData: [x1, y1],
callbacks: tf.callbacks.earlyStopping({
monitor: "val_acc" }),
});
console.log("the value of val_acc is :",
history.history.val_acc);