Problem in input shape Keras-LSTM
I want to make a predictor using Keras LSTM model. I have a sequence of places visited. The task is to predict the last destination.
I went through different examples but it seems I am not able to shape the input properly.
I am stuck on how to prepare in my program my data to give them to the LSTM model. Here is a minimum code related to my problem.
input_csv ='input.csv'
max_features = 6
df = pd.read_csv(input_csv)
df.head()
#Cafe =0.1, Park =0.2, Shop =0.3, Home=0.4, Movie = 0.5, School=0.6
For example, Person A visited cafe (0.1) - park(0.2) - cafe (0.1) - park(0.2) and finally ended at school(0.6). The desired task is to predict y (end) based on input X (place1,place2,place3,place4).
X = df.iloc[:,1:5].to_numpy()
X_train = X.reshape(6, 1, 4) # X.reshape(samples, timesteps, features)
X_train.shape
#(6, 1, 4)
y = df.iloc[:,-1].to_numpy()
y.shape
#(6,)
#Building model
model = Sequential()
model.add(LSTM(6, dropout=0.2, recurrent_dropout=0.2, input_shape=(None, 1)))
model.add(Dense(max_features, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
# Train
model.fit(X_train,y)
pred = model.predict(X_train)
predict_classes = np.argmax(pred,axis=1)
ValueError: Error when checking input: expected lstm_4_input to have shape (None, 1) but got array with shape (1, 4)
I would appreciate if someone could help me in clearing my confusion or pointing to some explanations. Thank You.
Category Data Science