这里面就4种标签,为什么里面说8超出了范围

问题遇到的现象和发生背景

index 8 is out of bounds for axis 1 with size 4

问题相关代码,请勿粘贴截图

print(pd.value_counts(y_train))
class_num = len(np.unique(y_train))
print(class_num)
#onehot编码
y_train = to_categorical(y=y_train, num_classes=class_num)
print(y_train.shape)

运行结果及报错内容

0.0 2429
1.0 2429
3.0 2429
8.0 2429
dtype: int64
4
IndexError: index 8 is out of bounds for axis 1 with size 4

我的解答思路和尝试过的方法

这里面就4种标签,为什么里面说8超出了范围

我想要达到的结果

求解决,谢谢

代码再贴全一些