Python InvalidArgumentError:索引[0,0]=-1不在[0,10]中

Python InvalidArgumentError:索引[0,0]=-1不在[0,10]中,python,tensorflow,deep-learning,keras,lstm,Python,Tensorflow,Deep Learning,Keras,Lstm,在LSTM和卷积中,它可以很好地与MLP进行二元分类,但是它给出了无效的arguminterror 我发现y需要重塑,我做到了。 我尝试了所有正值的x,模型运行良好。 那么负值有什么问题呢? 代码中给出了数据。有什么想法吗 错误如下: --------------------------------------------------------------------------- InvalidArgumentError Traceback (mos

在LSTM和卷积中,它可以很好地与MLP进行二元分类,但是它给出了
无效的arguminterror

我发现y需要重塑,我做到了。 我尝试了所有正值的x,模型运行良好。 那么负值有什么问题呢? 代码中给出了数据。有什么想法吗

错误如下:

---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
/usr/local/src/conda3_runtime/home/envs/DSX-Python35-Spark/lib/python3.5/site-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
   1326     try:
-> 1327       return fn(*args)
   1328     except errors.OpError as e:
....
File "/usr/local/src/conda3_runtime/home/envs/DSX-Python35-Spark/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1204, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): indices[0,0] = -1 is not in [0, 10)
     [[Node: embedding_11/Gather = Gather[Tindices=DT_INT32, Tparams=DT_FLOAT, validate_indices=true, _device="/job:localhost/replica:0/task:0/cpu:0"](embedding_11/embeddings/read, _arg_embedding_11_input_0_3)]]
代码:


你应该给出错误的完整输出,我猜你的y形状是[1,10]而不是[10]?y=np.array(y).transpose()?谢谢。我不知道如何给出完整输出,这就是为什么我给出了一小段数据。我尝试了y=np.array(y).transpose()。仍然给出相同的错误。我的意思是将最近的回溯语句中的错误粘贴到尾端。我尝试复制错误,但错误很长,导致共享错误。我从开始和结束都放置了一些错误。但是,代码已准备好在编辑器中运行。它的工作原理与原样一样。嘿!我尝试了x的正值,效果很好而不是代码“x=np.random.randint(5,size=(10,4))”中的x。现在我正在搜索负值的错误。
from keras.models import Sequential
from keras.layers import Dense, Embedding
from keras.layers import LSTM

max_features=10
maxlen=4
embedding_size=4
lstm_output_size = 1
batch_size = 2
epochs = 2

x=([[ 0,  6,  1,  0],
       [-1,  0,  0,  1],
       [ 4, -4,  3,  0],
       [-1,  9,  1, -5],
       [-2,  0,  0,  0],
       [ 2,  0,  4,  1],
       [ 4, 10, -4, -4],
       [ 0, 10, -1, -4],
       [ 3, -2,  2,  1],
       [ 0, -1,  0,  0]])

y=([[0, 1, 0, 0, 1, 0, 0, 0, 0, 1]])

x, y = np.array(x), np.array(y)
y = y.reshape((10, 1))

from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2)


print('Build model...')
model = Sequential()
model.add(Embedding(max_features, 64, input_length = maxlen ))
model.add(LSTM(64, activation="sigmoid", return_sequences=True, recurrent_activation="hard_sigmoid"))
model.add(Dropout(0.25))
model.add(LSTM(lstm_output_size))
model.add(Dense(1, activation='sigmoid'))

model.compile(loss='binary_crossentropy',
              optimizer='adam',
              metrics=['accuracy'])

print('Train...')
model.fit(x_train, y_train,
          batch_size=batch_size,
          epochs=epochs,
          validation_data=(x_test, y_test))
score, acc = model.evaluate(x_test, y_test,
                            batch_size=batch_size)

print('Test score:', score)
print('Test accuracy:', acc)