@@ -117,27 +117,29 @@ def lin_reg(X,theta):
117117
118118
119119
120- def prep_data (X ,y ,test_size ):
121- X_train , X_test , y_train , y_test = cross_validation .train_test_split (X , y , test_size = 0.4 )
122- return X_train ,X_test ,y_train ,y_test
123- 124- 125- 126120"""
127121Loading and training on toy dataset (boston land prices)
128122"""
129123
130124boston = datasets .load_boston ()
131125
132- 126+ """
127+ linear regression with multiple variables
128+ """
133129X = boston .data
134130y = boston .target
135131
132+ """
133+ #linear regression with single variable
134+ X = np.asmatrix(boston.data[:,0]).T #taking only the 1st column
135+ y = boston.target
136+ """
136137
137- 138138
139139X_train , X_test , y_train , y_test = cross_validation .train_test_split (X , y , test_size = 0.4 )
140140
141+ 142+ 141143normal_eqn_theta = np .asmatrix (normal_eqn_theta (X_train ,y_train )).T
142144
143145
@@ -151,5 +153,5 @@ def prep_data(X,y,test_size):
151153
152154
153155
154- print "MSE for normal_eqn Theta is: " , mean_squared_error (y_test , pred1 )
155- print "MSE for gradient_desc Theta is: " , mean_squared_error (y_test , pred2 )
156+ print "MSE for prediction using normal_eqn Theta is: " , mean_squared_error (y_test , pred1 )
157+ print "MSE for prediction using gradient_desc Theta is: " , mean_squared_error (y_test , pred2 )
0 commit comments