私は単純なMNISTの例を練習していますが、タイトルのようなエラーが発生し、インデックス11513が何を意味するのか分かりません。 以下は完全なコードです。インデックス11513は軸0のサイズが10000の範囲外です
np.random.seed(3)
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_val = x_train[50000:]
y_val = y_train[50000:]
x_train = x_train[:50000]
y_train = y_train[:50000]
x_train = x_train.reshape(50000, 784).astype('float32')/255.0
x_val = x_val.reshape(10000, 784).astype('float32')/255.0
x_test = x_test.reshape(10000, 784).astype('float32')/255.0
train_rand_idxs = np.random.choice(50000, 700)
val_rand_idxs = np.random.choice(10000, 300)
x_train = x_train[train_rand_idxs]
y_train = y_train[train_rand_idxs]
x_val = x_val[train_rand_idxs]#***This is where the error occurred***
y_val = y_val[train_rand_idxs]
y_train = np_utils.to_categorical(y_train)
y_test = np_utils.to_categorical(y_test)
y_val = np_utils.to_categorical(y_val)
model = Sequential()
model.add(Dense(units=2 , input_dim= 28*28, activation='relu'))
model.add(Dense(units=10 , activation='softmax'))
model.compile(loss='categorical_crossentropy' , optimizer='sgd' , metrics= ['accuracy'])
hist = model.fit(x_train, y_train, epochs =1000 , batch_size=10 , validation_data =(x_val, y_val))
インデックス11513は、リストの11514番目の要素です。エラーによると、あなたのリストは10000の要素しか持っていません –