'ValueError: setting an array element with a sequence for X_train, y_train
I am trying to fit my model on X_train and y_train as below:
model = Sequential()
model.add(LSTM(256, input_shape=(n_timesteps,n_features),recurrent_activation='hard_sigmoid'))
model.add(Dense(16))
model.add(Dense(n_outputs, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['acc'])
history = model.fit(X_train, y_train, epochs=5, batch_size=72, validation_split=0.1,
verbose=1)
where,
X_train: (429591, 5, 11)
X_test: (47733, 5, 11)
y_train: (429591,)
y_test: (47733,)
In order to do so, I got the error as ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type int).
To fix this error, I was using below code however, I got another error as ValueError: setting an array element with a sequence.
X_train.dtype is dtype('O')
X_train[0] looks like
array([[3, 30, 4, 399, 696, 60, 212, 0, 303, 981,
list([-2.1380737, 1.9840922, -0.21595824, 1.7971923, -0.49482924])],
[3, 30, 4, 399, 696, 60, 212, 0, 303, 981,
list([-2.1380737, 1.9840922, -0.21595824, 1.7971923, -0.49482924])],
[3, 30, 4, 399, 696, 60, 212, 0, 303, 981,
list([-2.1380737, 1.9840922, -0.21595824, 1.7971923, -0.49482924])],
[3, 30, 4, 399, 696, 60, 212, 0, 303, 981,
list([-2.1380737, 1.9840922, -0.21595824, 1.7971923, -0.49482924])],
[3, 30, 4, 399, 696, 60, 212, 0, 303, 981,
list([-2.1380737, 1.9840922, -0.21595824, 1.7971923, -0.49482924])]],
dtype=object)
where last element of X_train i.e. list([-2.1380737, 1.9840922, -0.21595824, 1.7971923, -0.49482924])] is after applying word2vec,
and y_train[0] contains 0,1.
Can't figure out where am I wrong. Any suggestion would be very helpful.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
