Grayrigel
Grayrigel

Reputation: 3594

How to make sense of dense layer units as dimensionality of predicted data?

I am dealing with a dataset that contains a time series data of 2 features x,y coordinates. I am interesting in predicting the future x,y (as a tuple, if possible ) from previous coordinates. I am fairly new to deep learning and I am closely following this article on Kaggle

Intro to Recurrent Neural Networks LSTM | GRU

google search gave me the answer that input_shape in a LSTM layer expects a 3D tuple (batch_size, time_steps, feature). Based on this knowledge, I dived into 2D data (x,y) :

X_train = []
y_train = []
for i in range(60,len(train_set_scaled)):
   X_train.append(training_set_scaled[i-60:i,0:2])
   y_train.append(training_set_scaled[i,0:2])
X_train, y_train = np.array(X_train), np.array(y_train)
print X_train.shape
(6208,60,2)

Since, it was 3D tuple, I didn't reshape it and continued.

## model begins here 
regressor = Sequential()

regressor.add(LSTM(units=50, return_sequences=True, input_shape=(X_train.shape[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=2)) ## i am predicting future x,y 

My code works, I am slightly unsure about output. Is it really future x,y that I am predicting? because If I give units=3, I get 3D output and units=1, I get 1D output. What that really means? I guess I am forcing my network to converge to n outputs when I am giving units=n. Let me know if my question isn't clear.

Upvotes: 0

Views: 54

Answers (1)

dimstudio
dimstudio

Reputation: 154

Usually, after defining the model type you need to use the model.fit method to fit it to the data.

model.fit(X_train, y_train)

The size of the output is defined by the shape of y_train i.e. the size of the labels vector for training.

To predict y you should do something like

y_prob = model.predict(X_test) 

Hope this answer your question

Upvotes: 2

Related Questions