-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.html
More file actions
33 lines (25 loc) · 1004 Bytes
/
sample.html
File metadata and controls
33 lines (25 loc) · 1004 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<html>
<head>
<!-- load tensorflow.js file -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.11.2"></script>
</head>
<body>
<div id="output"></div>
</body>
<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: 500});
document.getElementById('output').innerText=
model.predict(tf.tensor2d([20],[1,1]));
}
learnLinear();
</script>
</html>