SkalskiP / ILearnDeepLearning.py

This repository contains small projects related to Neural Networks and Deep Learning in general. Subjects are closely linekd with articles I publish on Medium. I encourage you both to read as well as to check how the code works in the action.
https://medium.com/@skalskip
MIT License
1.32k stars 466 forks source link

Keyerror : 0 #55

Open MalavikaAR opened 2 years ago

MalavikaAR commented 2 years ago

I got an error while running the NumPy neural network code using my dataset, "'DataFrame' object has no attribute 'reshape'". Also then I ran using your dataset make_moons, and again I got an error "Keyerror: 0".

ln [19]:

Training

params_values = train(np.transpose(X_train), np.transpose(y_train.reshape((y_train.shape[0], 1))), NN_ARCHITECTURE, 10000, 0.01)[0]

KeyError Traceback (most recent call last)

in () 1 # Training ----> 2 params_values = train(np.transpose(X_train), np.transpose(y_train.reshape((y_train.shape[0], 1))), NN_ARCHITECTURE, 10000, 0.01)[0] KeyError: 0 Would you please help me with what to do? Is it necessary to take the transpose and reshaping the X and y??
SkalskiP commented 2 years ago

Hi @MalavikaAR 👋. ! Judging by the error I think that you are trying to pass pandas.DataFrame instead of numpy.array through the neural network.

MalavikaAR commented 2 years ago

Ohh, okay, I will try to change that in my dataset. But what was the issue in trying with make_moons??

MalavikaAR commented 2 years ago

Heyy @SkalskiP , I changed it to numpyarray, and that error was gone, thankyou, but now I got the following error:


KeyError Traceback (most recent call last)

in () 1 # Training ----> 2 params_values = train(np.transpose(X_train), np.transpose(y_train), NN_ARCHITECTURE, 10000, 0.01) 1 frames in update(params_values, grads_values, nn_architecture, learning_rate) 1 def update(params_values, grads_values, nn_architecture, learning_rate): 2 for layer_idx, layer in enumerate(nn_architecture): ----> 3 params_values["W" + str(layer_idx)] -= learning_rate * grads_values["dW" + str(layer_idx)] 4 params_values["b" + str(layer_idx)] -= learning_rate * grads_values["db" + str(layer_idx)] 5 KeyError: 'W0' Would you please help me? I noticed some other people have asked about the same error in your article in the 'medium'.
SkalskiP commented 2 years ago

@MalavikaAR could you please show me how did you use make_moons function?

MalavikaAR commented 2 years ago

@SkalskiP

https://colab.research.google.com/drive/1dkvOMq2AYuHlTYLHodQzmro1kweY5W3O#scrollTo=e9-aFcBbNlsx

Please take a look at this link. I have tried it in colab.

MalavikaAR commented 2 years ago

I just wanted to add, the error is gone when I deleted the last indexing [0] of ln: [19] and got an accuracy of 0.98. But I am not sure if it is the right thing to do.

ln : [19]

Training

params_values = train(np.transpose(X_train), np.transpose(y_train.reshape((y_train.shape[0], 1))), NN_ARCHITECTURE, 10000, 0.01)[0]