user798719
user798719

Reputation: 9869

How to calculate input_dim for a keras sequential model?

Keras Dense layer needs an input_dim or input_shape to be specified. What value do I put in there?

My input is a matrix of 1,000,000 rows and only 3 columns. My output is 1,600 classes.

What do I put there?

  1. dimensionality of the inputs (1000000, 1600)

  2. 2 because it's a 2D matrix

Upvotes: 13

Views: 22001

Answers (3)

Arijit Bhadra
Arijit Bhadra

Reputation: 31

In your case lets assume x and y=target variable and are look like as follows after feature engineering

x.shape
(1000000, 3)
y.shape
((1000000, 1600)
# as first layer in a sequential model:
model = Sequential()
model.add(Dense(32, input_shape=x.shape[1])) # Input layer
# now the model will take as input arrays of shape (*, 3)
# and output arrays of shape (*, 32)
...
...
model.add(Dense(y.shape[1],activation='softmax')) # Output layer

y.shape[1]= 1600, the number of output which is the number of classes you have, since you are dealing with Classification.

Upvotes: 3

ANUJ KUMAR
ANUJ KUMAR

Reputation: 31

X = dataset.iloc[:, 3:13]

meaning the X parameter having all the rows and 3rd column till 12th column inclusive and 13th column exclusive. We will also have a X0 parameter to be given to the neural network, so total

input layers becomes 10+1 = 11.

Dense(input_dim = 11, activation = 'relu', kernel_initializer = 'he_uniform')

Upvotes: 1

Dr. Snoopy
Dr. Snoopy

Reputation: 56417

input_dim is the number of dimensions of the features, in your case that is just 3. The equivalent notation for input_shape, which is an actual dimensional shape, is (3,)

Upvotes: 21

Related Questions