我是一个学习机器学习并尝试训练神经网络的初学者。但是我运行代码时出现问题。错误说“ IndexError:索引114超出了尺寸为93“的0轴的限制。这如何发生以及如何解决?如果可以的话,请先谢谢您
这是我使用neupy库的代码
optimizer = algorithms.LevenbergMarquardt(
[
layers.Input(6),
layers.Sigmoid(12),
layers.Relu(6),
],
shuffle_data=True,
verbose=True,
)
print("Training...")
optimizer.train(X_train, X_test, y_train, y_test,epochs=100)
输入是glcm的6个功能,具有6个标签输出。我已经使用train_test_split
将数据分为测试和培训数据。
这是我分割的数据
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
print("Jumlah data latih : ", len(X_train))
print("Jumlah data uji : ", len(y_train))
print("Jumlah data latih : ", len(X_test))
print("Jumlah data uji : ", len(y_test))
Jumlah数据记录:372 Jumlah Data JI:372 Jumlah数据记录:93 Jumlah数据uji:93
这是错误消息
IndexError Traceback (most recent call last)
<ipython-input-8-8e9b3836f4ce> in <module>()
16
17 print("Training...")
---> 18 optimizer.train(X_train, X_test, y_train, y_test,epochs=100)
19
20 p = optimizer.predict(testdata)
5 frames
/usr/local/lib/python3.6/dist-packages/neupy/algorithms/gd/base.py in train(self, X_train, y_train, X_test, y_test, *args, **kwargs)
299 X_train=X_train, y_train=y_train,
300 X_test=X_test, y_test=y_test,
--> 301 *args, **kwargs)
302
303 def one_training_update(self, X_train, y_train):
/usr/local/lib/python3.6/dist-packages/neupy/algorithms/base.py in train(self, X_train, y_train, X_test, y_test, epochs, batch_size)
264 )
265
--> 266 for X_batch, y_batch in iterator:
267 self.events.trigger('update_start')
268 update_start_time = time.time()
/usr/local/lib/python3.6/dist-packages/neupy/utils/iters.py in minibatches(inputs, batch_size, shuffle)
64 for index in range(n_batches):
65 batch_slice = slice(index * batch_size, (index + 1) * batch_size)
---> 66 yield apply_slices(inputs, indices[batch_slice])
67
68 elif n_batches != 1:
/usr/local/lib/python3.6/dist-packages/neupy/utils/iters.py in apply_slices(inputs, indices)
30
31 if isinstance(inputs, (list, tuple)):
---> 32 return [apply_slices(input_, indices) for input_ in inputs]
33
34 return inputs[indices]
/usr/local/lib/python3.6/dist-packages/neupy/utils/iters.py in <listcomp>(.0)
30
31 if isinstance(inputs, (list, tuple)):
---> 32 return [apply_slices(input_, indices) for input_ in inputs]
33
34 return inputs[indices]
/usr/local/lib/python3.6/dist-packages/neupy/utils/iters.py in apply_slices(inputs, indices)
32 return [apply_slices(input_, indices) for input_ in inputs]
33
---> 34 return inputs[indices]
35
36
IndexError: index 114 is out of bounds for axis 0 with size 93
答案 0 :(得分:0)
我不确定100%使用的是哪个库。但是,为什么要在测试中加入测试设备?测试集用于某种验证或评估功能。尝试在训练功能中删除x_test和y_test。 即Optimizer.train(X_train,y_train,epochs = 100)