-1

我是一名学习机器学习并尝试训练神经网络的初学者。但是当我运行我的代码时出现问题。错误提示“IndexError: index 114 outside the limit for 0 axis with size 93”。这怎么会发生以及如何解决它?如果你能帮助我,请提前谢谢你

这是我使用 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)

输入是具有 6 个标签输出的 glcm 的 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 数据 uji: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
4

1 回答 1

0

我不能 100% 确定您使用的是哪个库。但是你为什么要把测试集放在训练中呢?测试集用于某种验证或评估功能。尝试删除训练函数中的 x_test 和 y_test。即优化器.train(X_train, y_train,epochs=100)

于 2019-04-25T16:04:15.967 回答