jiehou commited on
Commit
85c6519
·
1 Parent(s): b95ad10

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -117,17 +117,17 @@ def gradient_descent(intercept=4, slope=3, intercept_random=4, slope_random=3, g
117
  plt.contourf(b,w,Z, 50, alpha=0.5, cmap=plt.get_cmap('jet'))
118
 
119
  ### (5.5) Add optimal loss
120
- #plt.plot(theta0_best, theta1_best, 'x', ms=12, markeredgewidth=3, color='orange')
121
- #plt.text(theta0_best, theta1_best,'MSE:'+str(np.round(cal_mse(X,y,theta0_best, theta1_best),2)), color='red', fontsize=22)
122
 
123
  ### (5.6) Add loss of random lines
124
- #if intercept_random != intercept or slope_random != slope: #avoid overlap
125
- #plt.plot(intercept_random, slope_random, 'o', ms=5, markeredgewidth=3, color='orange')
126
- #plt.text(intercept_random, slope_random,'MSE:'+str(np.round(cal_mse(X,y,intercept_random, slope_random),2)), fontsize=22)
127
 
128
  ### (5.7) draw gradient updates
129
- #if gradient_descent:
130
- # plt.plot(b_history, w_history, 'o-', ms=3, lw=1.5, color='black')
131
 
132
 
133
 
 
117
  plt.contourf(b,w,Z, 50, alpha=0.5, cmap=plt.get_cmap('jet'))
118
 
119
  ### (5.5) Add optimal loss
120
+ plt.plot(theta0_best, theta1_best, 'x', ms=12, markeredgewidth=3, color='orange')
121
+ plt.text(theta0_best, theta1_best,'MSE:'+str(np.round(cal_mse(X,y,theta0_best, theta1_best),2)), color='red', fontsize=22)
122
 
123
  ### (5.6) Add loss of random lines
124
+ if intercept_random != intercept or slope_random != slope: #avoid overlap
125
+ plt.plot(intercept_random, slope_random, 'o', ms=5, markeredgewidth=3, color='orange')
126
+ plt.text(intercept_random, slope_random,'MSE:'+str(np.round(cal_mse(X,y,intercept_random, slope_random),2)), fontsize=22)
127
 
128
  ### (5.7) draw gradient updates
129
+ if gradient_descent:
130
+ plt.plot(b_history, w_history, 'o-', ms=3, lw=1.5, color='black')
131
 
132
 
133