diff --git a/live-0011/tfjs-linear-regressor.html b/live-0011/tfjs-linear-regressor.html index bf34960..df35cb6 100644 --- a/live-0011/tfjs-linear-regressor.html +++ b/live-0011/tfjs-linear-regressor.html @@ -19,35 +19,13 @@

🧠 Training a Linear Regressor in TF.js

const name = "Nono"; console.log(`JavaScript & ${name} script says hello! 👋`); - // Define our TensorFlow model - const model = tf.sequential({ - layers: [ - tf.layers.dense({units: 1, inputShape: [1]}) - ] - }); - + // Define your TensorFlow.s model + const model = tf.sequential({ layers: [ tf.layers.dense({units: 1, inputShape: [1]}) ] }); + // Compile it model.compile({loss: 'meanSquaredError', optimizer: 'sgd'}); - - const onEpochEnd = (epoch, logs) => { - console.log(`Epoch ${epoch} Loss: ${logs.loss}`); - model.predict(tf.tensor2d([5], [1, 1])).print(); - } - - const xs = tf.tensor2d([1, 2, 3, 4, 12, -10], [6, 1]); - const ys = tf.tensor2d([1, 3, 5, 7, 23, -21], [6, 1]); - - // Train the model using the data. - console.log(`Training the model..`); - - const config = { - callbacks: {onEpochEnd}, - epochs: 300 - }; - - model.fit(xs, ys, config).then(() => { - model.predict(tf.tensor2d([5], [1, 1])).print(); - console.log(`Epoch`); - }); + // And train! + model.fit(xs, ys, config); + console.log(`Done!`); // Sample function to predict on the console