Example #1
0
XX_poly_test = np.vstack([np.ones((X_poly_test.shape[0],)),X_poly_test.T]).T
XX_poly_val = np.vstack([np.ones((X_poly_val.shape[0],)),X_poly_val.T]).T

#######################################################################
## =========== Part 5: Learning Curve for Polynomial Regression ======#
#######################################################################

reg = 0.0
reglinear_reg2 = RegularizedLinearReg_SquaredLoss()
<<<<<<< HEAD
theta_opt0 = reglinear_reg2.train(XX_poly,y,reg=reg,num_iters=10000)
print 'Theta at lambda = 0 is ', theta_opt0

# plot data and training fit for the 6th order polynomial and save it in fig9.pdf

plot_utils.plot_fit(X,y,np.min(X),np.max(X),mu,sigma,theta_opt0,p,'Change in water level (x)','Water flowing out of dam (y)','Polynomial Regression fit with lambda = 0 and polynomial features of degree = ' + str(p))
=======
theta_opt1 = reglinear_reg1.train(XX_poly,y,reg=reg,num_iters=10000)
print 'Theta at lambda = 0 is ', theta_opt1


# plot data and training fit for the 6th order polynomial and save it in fig9.pdf

plot_utils.plot_fit(X,y,np.min(X),np.max(X),mu,sigma,theta_opt1,p,'Change in water level (x)','Water flowing out of dam (y)','Polynomial Regression fit with lambda = 0 and polynomial features of degree = ' + str(p))
>>>>>>> 89dd6a53aa0ff700b713b57c5d8d001424557b1d

plt.savefig('fig9.pdf')

# plot learning curve for data (6th order polynomail basis function) and save
# it in fig10.pdf
Example #2
0
XX_poly_test = np.vstack([np.ones((X_poly_test.shape[0],)),X_poly_test.T]).T
XX_poly_val = np.vstack([np.ones((X_poly_val.shape[0],)),X_poly_val.T]).T

#######################################################################
## =========== Part 5: Learning Curve for Polynomial Regression ======#
#######################################################################

reg = 0.0
reglinear_reg2 = RegularizedLinearReg_SquaredLoss()
theta_opt1 = reglinear_reg1.train(XX_poly,y,reg=reg,num_iters=10000)
print 'Theta at lambda = ' + str(reg) + ' is ', theta_opt1


# plot data and training fit for the 6th order polynomial and save it in fig9.pdf

plot_utils.plot_fit(X,y,np.min(X),np.max(X),mu,sigma,theta_opt1,p,'Change in water level (x)','Water flowing out of dam (y)','PR fit with lambda = ' + str(reg) + ' and polynomial features of degree = ' + str(p))

plt.savefig('fig9.pdf')

# plot learning curve for data (6th order polynomail basis function) and save
# it in fig10.pdf

error_train,error_val = utils.learning_curve(XX_poly,y,XX_poly_val,yval,reg)
plot_utils.plot_learning_curve(error_train,error_val,reg)
plt.savefig('fig10.pdf')


#######################################################################
## =========== Part 6: Averaged learning curve         ===============#
#######################################################################