isds2020 icon indicating copy to clipboard operation
isds2020 copied to clipboard

got an error for 11.1.6

Open fxj483 opened this issue 5 years ago • 1 comments
trafficstars

my code for the update weights:

def update_weights(X_, y_, w_, eta): error = compute_error(y_, X_, w_) fod = X_.T.dot(error) w_[1:] += eta * np.dot(x_.T,error) w_[0] += eta * error.sum(

#answer for 11.1.6 w = np.zeros(1+X.shape[1]) for i in range(50): print(update_weights(y_train, X_train,w,0.001))

the error I got: image

It seems the error is about the training data, but my code for handling the data is the same as the solution provided.

Thank you in advance!

fxj483 avatar Aug 18 '20 14:08 fxj483

hi @fxj483 , the problem is this line update_weights(y_train, X_train,w,0.001). Your update_weights function expects the input (X_, y_, w_, eta) but you insert (y_train, X_train,w,0.001). You will have to switch y_train and X_train :) The ValueError gets raised in the net_input function where you are trying to multiply a vector of dim (122, ) with a vector of dim (8, ). This is not well defined as to why the value error gets raised.

Whenever you get a ValueError due to something with the dimensionality of your data, check the dimension of your feature matrix and target vector by, e.g. for the feature matrix, writing X.shape.

jsr-p avatar Aug 19 '20 07:08 jsr-p