While training I am getting an error

IndexError Traceback (most recent call last)
in
----> 1 l = train(X,Y,model,100,0.0002)

in train(X, Y, model, epochs, learning_rate, logs)
3
4 classes = 2
----> 5 Y_OHT = one_hot(Y,classes)
6
7 for ix in range(epochs):

in one_hot(y, depth)
6 m = y.shape[0]
7 y_oht = np.zeros((m,depth))
----> 8 y_oht[np.arange(m),y] = 1
9 #print(m)
10 return y_oht

IndexError: index 2 is out of bounds for axis 1 with size 2

Here is the link to my code:

Hi @Shivam-Goyal-209664276424532,

Can you please share the .ipynb notebook directly. It would be much faster and easier for me to debug the code then.

Thanks!

Hi @Shivam-Goyal-209664276424532,

It’s taking longer than expected to understand and debug your code. Until then, you can use the one hot encoding functionality provided by keras:
https://keras.io/api/utils/python_utils/#tocategorical-function
Or you can also use the pandas pd.get_dummies() function for the same results.
Also, ensure that value of y is never greater than or equal to the depth in one_hot_encode function.

Okay bhaiya, will do!

Actually I found the error, my y was greater than my depth. Thanks a lot!!!

1 Like

That’s great Shivam!