🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to AI Notes
Topic #26

Ex1 Training


Training Function

Example

async function trainModel(model, inputs, labels, surface) {
  const batchSize = 25;
  const epochs = 50;
  const callbacks = tfvis.show.fitCallbacks(surface, ['loss'], {callbacks:['onEpochEnd']})
  return await model.fit(inputs, labels,
    {batchSize, epochs, shuffle:true, callbacks:callbacks}
  );
}

epochs defines how many iterations (loops) the model will do.

model.fit is the function that runs the loops.

callbacks defines the callback function to call when the model wants to redraw the graphics.


Test the Model

When a model is trained, it is important to test and evaluate it.

We do this by inspecting what the model predicts for a range of different inputs.

But, before we can do that, we have to un-normalize the data:

Un Normalize

let unX = tf.linspace(0, 1, 100);

let unY = model.predict(unX.reshape([100, 1]));

const unNormunX = unX.mul(inputMax.sub(inputMin)).add(inputMin);
const unNormunY = unY.mul(labelMax.sub(labelMin)).add(labelMin);

unX = unNormunX.dataSync();
unY = unNormunY.dataSync();

Then we can look at the result:

Plot the Result

const predicted = Array.from(unX).map((val, i) => {
  return {x: val, y: unY[i]}
});

// Plot the Result
tfPlot([values, predicted], surface1)

Want to go beyond the notes?

Join CodingNow 2.0's AI course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Ex1 Training – FAQs

Quick answers about learning Ex1 Training in AI.

This free note from CodingNow 2.0 explains Ex1 Training in AI — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every AI topic on CodingNow 2.0, including Ex1 Training, is 100% free with no signup required.
With focused practice, most students grasp Ex1 Training in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now