1
$\begingroup$

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 = data = pd.read_excel(....\testing_data.xlsx',sheet_name="i1-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')
])

model.compile(optimizer='adam',
              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)
$\endgroup$
  • $\begingroup$ What exactly isn't working? $\endgroup$ – Ben Reiniger Sep 11 '19 at 12:21
  • $\begingroup$ Well, I am having an issue about the line model.fit(training_data_X,....) It says its not possible or something like that. $\endgroup$ – Fexion Sep 11 '19 at 16:17
0
$\begingroup$

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.

| improve this answer | |
$\endgroup$
  • $\begingroup$ 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.. $\endgroup$ – Fexion Sep 11 '19 at 20:30
  • $\begingroup$ 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 $\endgroup$ – Leevo Sep 11 '19 at 20:36
  • $\begingroup$ Thank you for your helps! $\endgroup$ – Fexion Sep 11 '19 at 20:37
0
$\begingroup$

Another issue with your model is that, since you are in a regression setting, accuracy is meaningless (it is meaningful only in classification settings).

So, you should remove the metrics=['accuracy'] argument from your model compilation, so that model.evaluate returns the loss only (discard also val_acc).

See the SO thread What function defines accuracy in Keras when the loss is mean squared error (MSE)? for more details.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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