-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecond.html
More file actions
54 lines (54 loc) · 2.05 KB
/
second.html
File metadata and controls
54 lines (54 loc) · 2.05 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<html>
<head>
<title>should I give this guy money?</title>
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.14.1/dist/tf.min.js"></script>
<script>
//smart,good idea, is rich
function func(){
model.predict(x).print();
var iq =parseInt(prompt("is he/she smart??(1/0)"));
var idea=parseInt(prompt("does he/she have a good idea?(1/0)"));
var rich = parseInt(prompt("is he/she rich?(1/0)"));
document.body.innerHTML="<p style='font-family: sans-serif'>the probability of this turning out to be a good investment is: </p>";
console.log("training complete");
document.body.innerHTML+=Math.ceil(model.predict(tf.tensor2d([[iq,idea,rich]])).dataSync()*100);
document.body.innerHTML+="<button onclick='func()'>more prediction</button>"
}
var xs=[[1,0,1],[0,1,0],[1,0,1],[1,1,1],[0.56,1,1],[0.89,0,0],[0.50,0,0],[0.80,1,1],[0.29,0,1],[0.920,1,0],[0.810,0.5,1],[0.100,0.5,0.7],[0,0,0]];
var ys=[[0.06],[1],[1],[0.789],[1],[1],[0.678],[0.5234],[0.28],[0.999],[0.234],[0.96],[0]];
document.body.innerHTML="<p style='font-family: sans-serif'>pls wait the program is still training</p>";
const x=tf.tensor2d(xs);
const y=tf.tensor2d(ys);
const model=tf.sequential();
const hidden = tf.layers.dense({
units:4,
inputShape:[3],
activation:'sigmoid'
});
const output = tf.layers.dense({
units:1,
activation:'sigmoid'
});
model.add(hidden);
model.add(output);
const config = {
optimizer:tf.train.sgd(0.3),
loss:tf.losses.absoluteDifference
}
model.compile(config);
train().then(function (){
func();
document.body.innerHTML+="<button onclick='func()'>more prediction</button>"
});
async function train(){
for(let i=0;i<1000;i++){
const h = await model.fit(x,y,{epochs:10});
console.log(h.history.loss[0]);
}
}
</script>
<span id="span"></span>
</body>
</html>