abjer / isds2020

Introduction to Social Data Science 2020 - a summer school course abjer.github.io/isds2020
58 stars 92 forks source link

got an error for 11.1.6 #38

Open fxj483 opened 4 years ago

fxj483 commented 4 years ago

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: 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!

jsr-p commented 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.