What shape does data need to be in to fit in a Keras model?

Hey,

i have a matrix of data that i want to feed in my neural network. The raw data has a shape of (896000,6). As i need one dimension to be 128 elements i have two coices: (7000, 128, 6) or (7000, 6, 128). I know that the first dimension is the batch dimension. My question is, what is the correct shape for my Keras model?
Is there a rule of thumb to these kind of problems?
Thanks in advance.

@Palettenbrett,

Can you tell us why you want one dimension to be 128 elements?

Thank you!

Thanks for your reply,

the dimension with 128 elements was chosen by me.
My network needs to be quite small, so i chose an input of 128 datapoints.
But no particular reason why exaxtly 128.

@Palettenbrett,

The correct shape for your keras model will depend on the architecture of the model and the specific task you are trying to accomplish.

The raw data has a shape of (896000,6). As i need one dimension to be 128 elements

If you are working with time-series data and you want to pass 128 time-steps at a time to your model you can reshape your data to (7000, 128, 6).

Thank you!

Yes, it is basically time-series data. (7000, 128, 6) seems logical.
But what diffrence would it make if i reshape it to (7000, 6, 128)?
How do you decide on how the dimensions are distributed?
Or does it not matter at all?

If your data is time-series data, reshaping it to (7000, 6, 128) would not make sense as it would not align with the expected input shape of the time-series model.

In this case, the first dimension is the batch size, the second dimension is the number of features and the third dimension is the number of time steps. Here the model interprets the data as having 128 separate features rather than 128 time steps of the same 6 features, so the order is very important.

Thank you!

1 Like

I think this helps.
Thank you very much!

In Keras, the data used to train and evaluate a model needs to be in the form of NumPy arrays. The shape of the data depends on the type of model being used and the number of dimensions of the input data.

For example, if you are training a feedforward neural network (also known as a multilayer perceptron), the input data should be a 2D array with shape (num_samples, num_features).The num_samples dimension corresponds to the number of examples in your dataset, and the num_features dimension corresponds to the number of input features for each example.

1 Like