durrani commited on
Commit
f616e96
·
1 Parent(s): 7fb8c2b
Files changed (1) hide show
  1. app.py +5 -6
app.py CHANGED
@@ -20,11 +20,10 @@ while iter_count < max_iters:
20
  # Compute the predicted output
21
  y_pred = [Theta0 + Theta1 * x1[i] + Theta2 * x2[i] for i in range(len(x1))]
22
 
23
-
24
  # Compute the errors
25
  errors = [y_pred[i] - y_actual[i] for i in range(len(x1))]
26
 
27
- # Update Theta0 and Theta1
28
  Theta0 -= alpha * sum(errors) / len(x1)
29
  Theta1 -= alpha * sum([errors[i] * x1[i] for i in range(len(x1))]) / len(x1)
30
  Theta2 -= alpha * sum([errors[i] * x2[i] for i in range(len(x2))]) / len(x2)
@@ -34,7 +33,7 @@ while iter_count < max_iters:
34
 
35
  # Print the cost function every 100 iterations
36
  if iter_count % 100 == 0:
37
- print("Iteration {}: Cost = {}, Theta0 = {}, Theta1 = {}".format(iter_count, cost, Theta0, Theta1, Theta2))
38
 
39
  # Check for convergence (if the cost is decreasing by less than 0.0001)
40
  if iter_count > 0 and abs(cost - prev_cost) < 0.0001:
@@ -45,7 +44,7 @@ while iter_count < max_iters:
45
  iter_count += 1
46
  prev_cost = cost
47
 
48
- # Print the final values of Theta0 and Theta1
49
- print("Final values: Theta0 = {}, Theta1 = {}".format(Theta0, Theta1, Theta2))
50
- print("Final Cost: Cost= {}".format(cost))
51
  print("Final values: y_pred = {}, y_actual = {}".format(y_pred, y_actual))
 
20
  # Compute the predicted output
21
  y_pred = [Theta0 + Theta1 * x1[i] + Theta2 * x2[i] for i in range(len(x1))]
22
 
 
23
  # Compute the errors
24
  errors = [y_pred[i] - y_actual[i] for i in range(len(x1))]
25
 
26
+ # Update Theta0, Theta1, and Theta2
27
  Theta0 -= alpha * sum(errors) / len(x1)
28
  Theta1 -= alpha * sum([errors[i] * x1[i] for i in range(len(x1))]) / len(x1)
29
  Theta2 -= alpha * sum([errors[i] * x2[i] for i in range(len(x2))]) / len(x2)
 
33
 
34
  # Print the cost function every 100 iterations
35
  if iter_count % 100 == 0:
36
+ print("Iteration {}: Cost = {}, Theta0 = {}, Theta1 = {}, Theta2 = {}".format(iter_count, cost, Theta0, Theta1, Theta2))
37
 
38
  # Check for convergence (if the cost is decreasing by less than 0.0001)
39
  if iter_count > 0 and abs(cost - prev_cost) < 0.0001:
 
44
  iter_count += 1
45
  prev_cost = cost
46
 
47
+ # Print the final values of Theta0, Theta1, and Theta2
48
+ print("Final values: Theta0 = {}, Theta1 = {}, Theta2 = {}".format(Theta0, Theta1, Theta2))
49
+ print("Final Cost: Cost = {}".format(cost))
50
  print("Final values: y_pred = {}, y_actual = {}".format(y_pred, y_actual))