2
$\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$
3
  • $\begingroup$ What exactly isn't working? $\endgroup$
    – Ben Reiniger
    Commented Sep 11, 2019 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
    Commented Sep 11, 2019 at 16:17
  • $\begingroup$ I'd just like to add a quick comment: you are doing regression, why using 'accuracy' as metrics? $\endgroup$
    – xshang
    Commented Apr 10, 2022 at 5:54

2 Answers 2

1
$\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.

$\endgroup$
3
  • $\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
    Commented Sep 11, 2019 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
    Commented Sep 11, 2019 at 20:36
  • $\begingroup$ Thank you for your helps! $\endgroup$
    – Fexion
    Commented Sep 11, 2019 at 20:37
0
$\begingroup$

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

$\endgroup$

Your Answer

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

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