Built with blockbuilder.org
xxxxxxxxxx
<!-- Example from https://www.youtube.com/watch?v=epSgXU3AyiI -->
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.11.2"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
</head>
<body>
<div id="output_field"></div>
<script>
async function learnLinear(){
const model = tf.sequential();
model.add(tf.layers.dense({units: 1, inputShape:[1]}));
model.compile({
loss: 'meanSquaredError',
optimizer: 'sgd'
});
const xs = tf.tensor2d([-1, 0, 1, 2, 3, 4],[6,1]);
const ys = tf.tensor2d([-3, -1, 1, 3, 5, 7],[6,1]);
await model.fit(xs, ys, {epochs: 250});
document.getElementById('output_field').innerText =
model.predict(tf.tensor2d([20], [1,1]));
}
learnLinear();
// Feel free to change or delete any of the code you see in this editor!
var svg = d3.select("body").append("svg")
.attr("width", 960)
.attr("height", 500)
svg.append("text")
.text("Edit the code below to change me!")
.attr("y", 200)
.attr("x", 120)
.attr("font-size", 36)
.attr("font-family", "monospace")
</script>
</body>
https://d3js.org/d3.v4.min.js
https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.11.2