HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
Try it Yourself »
async function trainModel(model, inputs, labels, surface) {
const batchSize = 25;
const epochs = 100;
const callbacks = tfvis.show.fitCallbacks(surface, ['loss'], {callbacks:['onEpochEnd']})
return await model.fit(inputs, labels,
{batchSize, epochs, shuffle:true, callbacks:callbacks}
);
}
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:
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:
const predicted = Array.from(unX).map((val, i) => {
return {x: val, y: unY[i]}
});
// Plot the Result
tfPlot([values, predicted], surface1)