'IndexError: index 5 is out of bounds for axis 1 with size 5
Tried to convert a column to categorical data for NN classification. The column has 6 classes
from tensorflow.keras.utils import to_categorical
y_train = to_categorical(y_train,num_classes=5)
y_test = to_categorical(y_test,num_classes=5)
The error obtained is
IndexError: index 5 is out of bounds for axis 1 with size 5.
What should I do to clear this?
Solution 1:[1]
If the column has 6 classes then why are you passing num_classes=5 in to_categorical.
Try
y_train = to_categorical(y_train,num_classes=6)
y_test = to_categorical(y_test,num_classes=6)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Prjvl |

