<html>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
<body>
<h2>TensorFlow.js</h2>
<p id="message">Model is training!</p>
<div id="myPlot" style="width:100%;max-width:700px"></div>
<script>
const xs = tf.tensor([0, 1, 2, 3, 4]);
const ys = xs.mul(1.2).add(5);
const model = tf.sequential();
model.add(tf.layers.dense({units:1, inputShape:[1]}));
model.compile({loss: 'meanSquaredError', optimizer:'sgd'});
model.fit(xs, ys, {epochs:500}).then(() => {myFunction()});
function myFunction() {
const xMax = 20;
const xArr = [];
const yArr = [];
for (let x = 10; x <= xMax; x++) {
let result = model.predict(tf.tensor([Number(x)]));
result.data().then(y => {
xArr.push(x);
yArr.push(Number(y));
if (x == xMax) {display(xArr,yArr)};
});
}
}
function display(xArr, yArr) {