Open fxj483 opened 4 years ago
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
.
my code for the update weights:
def updateweights(X, y, w, eta): error = computeerror(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:
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!