Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e17d624

Browse files
Update LinearRegression.py
added example for single and multi variable cases
1 parent ec57e8b commit e17d624

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

‎LinearRegression.py‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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
"""
127121
Loading and training on toy dataset (boston land prices)
128122
"""
129123

130124
boston = datasets.load_boston()
131125

132-
126+
"""
127+
linear regression with multiple variables
128+
"""
133129
X = boston.data
134130
y = 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

139139
X_train, X_test, y_train, y_test = cross_validation.train_test_split(X, y, test_size=0.4)
140140

141+
142+
141143
normal_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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /