Skip to content

Commit 61cf20d

Browse files
authored
Update script.js
1 parent 16632ac commit 61cf20d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Logistic Regression/script.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ async function cost_function(features, labels, weights,r){
9191
}
9292
async function train(features, labels, weights, lr, iters=100,r=0){
9393
cost_history =new Array();
94+
var bar=document.getElementById('bar');
9495
for(var i=0;i<iters;i++){
96+
bar.style.width=Math.ceil(i*100/(iters-1))+'%';
97+
bar.innerHTML=Math.ceil(i*100/(iters-1))+'%';
98+
9599
weights = await update_weights(features, labels, weights, lr,r);
96100
var cost = await cost_function(features, labels, weights,r);
97101
cost_history.push({x:i,y:Number(cost)});
@@ -104,6 +108,8 @@ async function train(features, labels, weights, lr, iters=100,r=0){
104108
}
105109

106110
async function trainclick(){
111+
var ele=document.getElementById('barc');
112+
ele.style.display="block";
107113
await loaddata();
108114
degree=Number(document.getElementById('d').value);
109115
var lr=tf.pow(tf.tensor(10),Number(document.getElementById('l').value));
@@ -117,9 +123,12 @@ async function trainclick(){
117123
var res=await train(X, y , initial_weight,lr,epoch,r);
118124
weights_calculated =res[0]; cost_history=res[1];
119125
await plotdecisionboundary();
120-
126+
ele.style.display="none";
127+
var bar=document.getElementById('bar');
128+
bar.style.width='0%';
129+
bar.innerHTML='';
121130
}
122-
trainclick();
131+
document.addEventListener('DOMContentLoaded',trainclick());
123132

124133
document.getElementById('train').addEventListener('click',trainclick);
125134

0 commit comments

Comments
 (0)