# Get multiple output from Keras

I have a regression problem which I have to predict 3 numerical values from a provided data. For example let's say I have a data set containing X1,X2,X3,X4,X5,X6...X100,Y1,Y2,Y3 columns. In this case I have to predict Y1,Y2,Y3 values. Is there are any way to construct the model to get all the outputs at the same time using Keras.

it's quite easy to make! One thing to note I'm using the Keras functional API.

from keras.layers import Input, Dense

Input_1= Input(shape=(shape, ))

x = Dense(100, activation='relu')(Input_1)
x = Dense(100, activation='relu')(x)
x = Dense(100, activation='relu')(x)

out1 = Dense(1,  activation='linear')(x)
out2 = Dense(1,  activation='linear')(x)
out3 = Dense(1,  activation='linear')(x)

model = Model(inputs=Input_1, outputs=[out1,out2,out3])
model.compile(optimizer = "rmsprop", loss = 'mse')


You can set your output layer to have 3 nodes. When you train, set your output to be a vector containing $$[Y_1, Y_2, Y_3]$$.

model.add(Dense(3, activation='linear'))


In above it is not mentioned that we have a linear regression, also adding dense layer will let model take different $$Y_i$$ simultaenously in beginnging, I wil still prefer \textbf{Model} Api from keras, as multioutput model

• For regression tasks the output layer should have linear activation. – Media Feb 20 '18 at 5:55