Commit
·
9c0f9ca
1
Parent(s):
9d43667
Update index.html
Browse files- index.html +26 -23
index.html
CHANGED
@@ -1,24 +1,27 @@
|
|
1 |
-
<!DOCTYPE html>
|
2 |
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<html>
|
2 |
+
<head>
|
3 |
+
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.11.2"></script>
|
4 |
+
</head>
|
5 |
+
<body>
|
6 |
+
<div id="output_field"></div>
|
7 |
+
</body>
|
8 |
+
<script>
|
9 |
+
async function learnLinear(){
|
10 |
+
const model = tf.sequential();
|
11 |
+
model.add(tf.layers.dense({units: 1, inputShape: [1]}));
|
12 |
+
model.compile({
|
13 |
+
loss: 'meanSquaredError',
|
14 |
+
optimizer: 'sgd'
|
15 |
+
});
|
16 |
+
|
17 |
+
const xs = tf.tensor2d([-1, 0, 1, 2, 3, 4], [6, 1]);
|
18 |
+
const ys = tf.tensor2d([-3, -1, 1, 3, 5, 7], [6, 1]);
|
19 |
+
|
20 |
+
await model.fit(xs, ys, {epochs: 500});
|
21 |
+
|
22 |
+
document.getElementById('output_field').innerText =
|
23 |
+
model.predict(tf.tensor2d([10], [1, 1]));
|
24 |
+
}
|
25 |
+
learnLinear();
|
26 |
+
</script>
|
27 |
+
<html>
|