# Multi-Output Regression with neural network in Keras

I have got an .xlsx Excel file with an input an 2 output columns. And there are some coordinates and outputs in that file such as: x= 10 y1=15 y2=20 x= 20 y1=14 y2=22 ... I am trying to do that regression using tensorflow. But somehow i can't manage to do it. I am leaving my code here, I would appraciate it if someone could help! I also have test datas ready as well.

training_data = pd.read_excel(...\training_data.xlsx',sheet_name="i1-o2")

training_data_X = training_data['i1']

training_data_Y = training_data[['o1','o2']]

testing_data_X = testing_data['i1']

testing_data_Y = testing_data[['o1','o2']]

model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(128, activation=tf.nn.relu),
tf.keras.layers.Dense(128, activation=tf.nn.relu),
tf.keras.layers.Dense(128, activation=tf.nn.relu),
tf.keras.layers.Dense(128, activation=tf.nn.relu),
tf.keras.layers.Dense(128, activation=tf.nn.relu),
tf.keras.layers.Dense(128, activation=tf.nn.relu),
tf.keras.layers.Dense(6, activation='linear')
])

loss='mean_squared_error',
metrics=['accuracy'])
model.fit(training_data_X,training_data_Y,epochs=10,batch_size=100)

val_loss,val_acc = model.evaluate(testing_data_X,testing_data_Y)
print(val_loss,val_acc)

• What exactly isn't working? – Ben Reiniger Sep 11 '19 at 12:21
• Well, I am having an issue about the line model.fit(training_data_X,....) It says its not possible or something like that. – Fexion Sep 11 '19 at 16:17

I found some mistakes:

1. input data must be numpy objects, not pandas
2. this Network has 6 output nodes, not 2
3. the number of layers is completely exagerated IMHO
4. the Flatten() layer at the beginning is not correct
5. the way you called ReLU's is not correct

This should be enough:

from tf.keras.models import Sequential
from tf.keras.layers import Dense
from tf.keras.activations import relu

model = Sequential([
tf.keras.layers.Dense(128, activation = relu),

tf.keras.layers.Dense(128, activation = relu),

tf.keras.layers.Dense(2, activation = None)
])


Check if the loss works at this point. Alternatively, you need to write your own custom loss function using Keras backend functions.

• Alright, It looks like i managed to fix the problems. The last thing that i would like to ask is if you could help me with drawing graph. Any tips? Thanx even if you cant help.. – Fexion Sep 11 '19 at 20:30
• I admit I never tried to draw graphs... But I'd suggest you to use the TensorBoard. There are other python libraries that can do that within Jupyter Notebook, but I admit I never looked for that. Sorry – Leevo Sep 11 '19 at 20:36
• Thank you for your helps! – Fexion Sep 11 '19 at 20:37

Why would you use a Flatten layer in this? seems like it is already a numerical data.

and as @desertnaut mentioned, since this is a regression setup, you should be using mse or mae