Update app.py
Browse files
app.py
CHANGED
|
@@ -78,7 +78,31 @@ def gradient_descent(intercept=4, slope=3, intercept_random=4, slope_random=3, g
|
|
| 78 |
w_history.append(w)
|
| 79 |
|
| 80 |
train_mse.append(cal_mse(X,y,b,w))
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
plt.xlabel("$x_1$", fontsize=22)
|
| 83 |
plt.ylabel("$y$", rotation=0, fontsize=22)
|
| 84 |
plt.xticks(fontsize=18)
|
|
|
|
| 78 |
w_history.append(w)
|
| 79 |
|
| 80 |
train_mse.append(cal_mse(X,y,b,w))
|
| 81 |
+
|
| 82 |
+
if i == int(iteration/4):
|
| 83 |
+
X_tmp = np.array([[0], [2]])
|
| 84 |
+
X_tmp_b = np.c_[np.ones((2, 1)), X_tmp] # add x0 = 1 to each instance
|
| 85 |
+
y_predict_tmp = X_tmp_b.dot(np.array([b, w]))
|
| 86 |
+
plt.plot(X_tmp, y_predict_tmp, "yellow", linewidth=2, label = "Fitted line in iteration "+str(i))
|
| 87 |
+
|
| 88 |
+
if i == int(iteration/3):
|
| 89 |
+
X_tmp = np.array([[0], [2]])
|
| 90 |
+
X_tmp_b = np.c_[np.ones((2, 1)), X_tmp] # add x0 = 1 to each instance
|
| 91 |
+
y_predict_tmp = X_tmp_b.dot(np.array([b, w]))
|
| 92 |
+
plt.plot(X_tmp, y_predict_tmp, "blue", linewidth=2, label = "Fitted line in iteration "+str(i))
|
| 93 |
+
|
| 94 |
+
if i == int(iteration/2):
|
| 95 |
+
X_tmp = np.array([[0], [2]])
|
| 96 |
+
X_tmp_b = np.c_[np.ones((2, 1)), X_tmp] # add x0 = 1 to each instance
|
| 97 |
+
y_predict_tmp = X_tmp_b.dot(np.array([b, w]))
|
| 98 |
+
plt.plot(X_tmp, y_predict_tmp, "gray", linewidth=2, label = "Fitted line in iteration "+str(i))
|
| 99 |
+
|
| 100 |
+
if i == int(iteration-1):
|
| 101 |
+
X_tmp = np.array([[0], [2]])
|
| 102 |
+
X_tmp_b = np.c_[np.ones((2, 1)), X_tmp] # add x0 = 1 to each instance
|
| 103 |
+
y_predict_tmp = X_tmp_b.dot(np.array([b, w]))
|
| 104 |
+
plt.plot(X_tmp, y_predict_tmp, "black", linewidth=2, label = "Fitted line in iteration "+str(i))
|
| 105 |
+
|
| 106 |
plt.xlabel("$x_1$", fontsize=22)
|
| 107 |
plt.ylabel("$y$", rotation=0, fontsize=22)
|
| 108 |
plt.xticks(fontsize=18)
|