I am currently struggling to understand how i should train my regression network using keras. I am not sure how I should pass my input data to the network.

Both the input data and the output data is stored as a list of numpy arrays.

Each input numpy array is a matrix which has (400 rows, x columns) Each output numpy array is a matrix which has (x number of rows, 13 columns)

So input dimension is 400 and output is 13. But how do I pass each of these sets within the list to the training?

# Multilayer Perceptron
model = Sequential()    # Feedforward
model.add(Dense(3, input_dim=400, output_dim=13))
model.compile('sgd', 'mse')

I know that model.fit trains the model given the parameter, how it actually takes in the data seems a bit like magic to me, and how it knows that the columns of matrix A should be mapped the rows of matrix B this has to be done for the whole matrix, appended to the list.


1 Answer 1


If you look at the Keras documentation, you will observe that for Sequential model's first layers takes the required input. So for example, your first layer is Dense layer with input dimension as 400. Hence each input should be a numpy array of size 400. You can pass a 2D numpy array with size (x,400). (I assume that x is the number of input examples). Your output has 13 dimensions for each output document and hence your final Dense layer has to be model.add(Dense(13)) instead of model.add(Dense(1)).

Coming to how it knows, it takes the first dimension of X as number of training examples and second dimension as the size of each example. Similarly for output layer.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.