from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
from keras.layers import Dropout
regressor=Sequential()
regressor.add(LSTM(units=50,return_sequences=True,input_shape=(X_train.shape[1],1)))
regressor.add(Dropout(0.2))
regressor.add(LSTM(units=50,return_sequences=True))
regressor.add(Dropout(0.2))
regressor.add(LSTM(units=50,return_sequences=True))
regressor.add(Dropout(0.2))
regressor.add(LSTM(units=50))
regressor.add(Dropout(0.2))
regressor.add(Dense(units=1))
regressor.compile(optimizer='adam',loss='mean_squared_error')
X_train = np.asarray(X_train).astype(np.float32)
regressor.fit(X_train,y_train,epochs=100,batch_size=32)
使用fit
方法后,出现此错误:
ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray)
如果有人有任何出路,请在这方面提供帮助