Regarding loss weighting in Keras regression problem for multiple outputs










0















I am running a Hyperas optimization for regression problem, with 3 predictors (X) and 2 targets (Y).



I did this, after ingesting the raw data:



X_train, X_val, Y_train, Y_val = train_test_split(X, Y, test_size=0.2, random_state=111)

# Input layers and Hidden Layers
model = Sequential()
model.add(Dense(choice([np.power(2,1),np.power(2,2),np.power(2,3),np.power(2,4),np.power(2,5)]), input_dim = X_train.shape[1]))
model.add(Activation(choice(['tanh','relu', 'sigmoid'])))
model.add(Dropout(uniform(0, 1)))
model.add(Dense(choice([np.power(2,1),np.power(2,2),np.power(2,3),np.power(2,4),np.power(2,5)])))
model.add(Activation(choice(['tanh','relu', 'sigmoid'])))
model.add(Dropout(uniform(0, 1)))

# Output layer
model.add(Dense(Y_train.shape[1]))
model.add(Activation('linear'))

model.compile(loss='mae', metrics=['mae'],optimizer=optimizer, loss_weights=[0.6,0.4])

history = model.fit(X_train, Y_train,
batch_size=choice([16,32,64,128]),
epochs=choice([20000]),
verbose=2,
validation_data=(X_val, Y_val),
callbacks=callbacks_list)


However, when running this, it says:



ValueError: When passing a list as loss_weights, it should have one entry per model output. The model has 1 outputs, but you passed loss_weights=[1, 1]


I'm guessing its due to the format of my inputs and outputs. However, I can't figure out the proper format for which I am supposed to feed it into the model.



Appreciate your advice please, thank you.










share|improve this question
























  • Your model has one output layer and one loss function. So the loss_weights does not make sense here, right? Don't confuse the the shape of output layer which is (2,) with the number of output layers. Loss functions are applied on the whole layers' output and not on each element of output layer individually.

    – today
    Nov 15 '18 at 13:27












  • ok so Sequential() cannot have more than one output layer right?

    – Corse
    Nov 15 '18 at 14:21






  • 1





    That's right. You need to use functional API instead if you want more flexibility.

    – today
    Nov 15 '18 at 14:24











  • alright, thank you!

    – Corse
    Nov 15 '18 at 14:36















0















I am running a Hyperas optimization for regression problem, with 3 predictors (X) and 2 targets (Y).



I did this, after ingesting the raw data:



X_train, X_val, Y_train, Y_val = train_test_split(X, Y, test_size=0.2, random_state=111)

# Input layers and Hidden Layers
model = Sequential()
model.add(Dense(choice([np.power(2,1),np.power(2,2),np.power(2,3),np.power(2,4),np.power(2,5)]), input_dim = X_train.shape[1]))
model.add(Activation(choice(['tanh','relu', 'sigmoid'])))
model.add(Dropout(uniform(0, 1)))
model.add(Dense(choice([np.power(2,1),np.power(2,2),np.power(2,3),np.power(2,4),np.power(2,5)])))
model.add(Activation(choice(['tanh','relu', 'sigmoid'])))
model.add(Dropout(uniform(0, 1)))

# Output layer
model.add(Dense(Y_train.shape[1]))
model.add(Activation('linear'))

model.compile(loss='mae', metrics=['mae'],optimizer=optimizer, loss_weights=[0.6,0.4])

history = model.fit(X_train, Y_train,
batch_size=choice([16,32,64,128]),
epochs=choice([20000]),
verbose=2,
validation_data=(X_val, Y_val),
callbacks=callbacks_list)


However, when running this, it says:



ValueError: When passing a list as loss_weights, it should have one entry per model output. The model has 1 outputs, but you passed loss_weights=[1, 1]


I'm guessing its due to the format of my inputs and outputs. However, I can't figure out the proper format for which I am supposed to feed it into the model.



Appreciate your advice please, thank you.










share|improve this question
























  • Your model has one output layer and one loss function. So the loss_weights does not make sense here, right? Don't confuse the the shape of output layer which is (2,) with the number of output layers. Loss functions are applied on the whole layers' output and not on each element of output layer individually.

    – today
    Nov 15 '18 at 13:27












  • ok so Sequential() cannot have more than one output layer right?

    – Corse
    Nov 15 '18 at 14:21






  • 1





    That's right. You need to use functional API instead if you want more flexibility.

    – today
    Nov 15 '18 at 14:24











  • alright, thank you!

    – Corse
    Nov 15 '18 at 14:36













0












0








0








I am running a Hyperas optimization for regression problem, with 3 predictors (X) and 2 targets (Y).



I did this, after ingesting the raw data:



X_train, X_val, Y_train, Y_val = train_test_split(X, Y, test_size=0.2, random_state=111)

# Input layers and Hidden Layers
model = Sequential()
model.add(Dense(choice([np.power(2,1),np.power(2,2),np.power(2,3),np.power(2,4),np.power(2,5)]), input_dim = X_train.shape[1]))
model.add(Activation(choice(['tanh','relu', 'sigmoid'])))
model.add(Dropout(uniform(0, 1)))
model.add(Dense(choice([np.power(2,1),np.power(2,2),np.power(2,3),np.power(2,4),np.power(2,5)])))
model.add(Activation(choice(['tanh','relu', 'sigmoid'])))
model.add(Dropout(uniform(0, 1)))

# Output layer
model.add(Dense(Y_train.shape[1]))
model.add(Activation('linear'))

model.compile(loss='mae', metrics=['mae'],optimizer=optimizer, loss_weights=[0.6,0.4])

history = model.fit(X_train, Y_train,
batch_size=choice([16,32,64,128]),
epochs=choice([20000]),
verbose=2,
validation_data=(X_val, Y_val),
callbacks=callbacks_list)


However, when running this, it says:



ValueError: When passing a list as loss_weights, it should have one entry per model output. The model has 1 outputs, but you passed loss_weights=[1, 1]


I'm guessing its due to the format of my inputs and outputs. However, I can't figure out the proper format for which I am supposed to feed it into the model.



Appreciate your advice please, thank you.










share|improve this question
















I am running a Hyperas optimization for regression problem, with 3 predictors (X) and 2 targets (Y).



I did this, after ingesting the raw data:



X_train, X_val, Y_train, Y_val = train_test_split(X, Y, test_size=0.2, random_state=111)

# Input layers and Hidden Layers
model = Sequential()
model.add(Dense(choice([np.power(2,1),np.power(2,2),np.power(2,3),np.power(2,4),np.power(2,5)]), input_dim = X_train.shape[1]))
model.add(Activation(choice(['tanh','relu', 'sigmoid'])))
model.add(Dropout(uniform(0, 1)))
model.add(Dense(choice([np.power(2,1),np.power(2,2),np.power(2,3),np.power(2,4),np.power(2,5)])))
model.add(Activation(choice(['tanh','relu', 'sigmoid'])))
model.add(Dropout(uniform(0, 1)))

# Output layer
model.add(Dense(Y_train.shape[1]))
model.add(Activation('linear'))

model.compile(loss='mae', metrics=['mae'],optimizer=optimizer, loss_weights=[0.6,0.4])

history = model.fit(X_train, Y_train,
batch_size=choice([16,32,64,128]),
epochs=choice([20000]),
verbose=2,
validation_data=(X_val, Y_val),
callbacks=callbacks_list)


However, when running this, it says:



ValueError: When passing a list as loss_weights, it should have one entry per model output. The model has 1 outputs, but you passed loss_weights=[1, 1]


I'm guessing its due to the format of my inputs and outputs. However, I can't figure out the proper format for which I am supposed to feed it into the model.



Appreciate your advice please, thank you.







python keras






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 9:45









Milo Lu

1,65711628




1,65711628










asked Nov 15 '18 at 13:22









CorseCorse

145110




145110












  • Your model has one output layer and one loss function. So the loss_weights does not make sense here, right? Don't confuse the the shape of output layer which is (2,) with the number of output layers. Loss functions are applied on the whole layers' output and not on each element of output layer individually.

    – today
    Nov 15 '18 at 13:27












  • ok so Sequential() cannot have more than one output layer right?

    – Corse
    Nov 15 '18 at 14:21






  • 1





    That's right. You need to use functional API instead if you want more flexibility.

    – today
    Nov 15 '18 at 14:24











  • alright, thank you!

    – Corse
    Nov 15 '18 at 14:36

















  • Your model has one output layer and one loss function. So the loss_weights does not make sense here, right? Don't confuse the the shape of output layer which is (2,) with the number of output layers. Loss functions are applied on the whole layers' output and not on each element of output layer individually.

    – today
    Nov 15 '18 at 13:27












  • ok so Sequential() cannot have more than one output layer right?

    – Corse
    Nov 15 '18 at 14:21






  • 1





    That's right. You need to use functional API instead if you want more flexibility.

    – today
    Nov 15 '18 at 14:24











  • alright, thank you!

    – Corse
    Nov 15 '18 at 14:36
















Your model has one output layer and one loss function. So the loss_weights does not make sense here, right? Don't confuse the the shape of output layer which is (2,) with the number of output layers. Loss functions are applied on the whole layers' output and not on each element of output layer individually.

– today
Nov 15 '18 at 13:27






Your model has one output layer and one loss function. So the loss_weights does not make sense here, right? Don't confuse the the shape of output layer which is (2,) with the number of output layers. Loss functions are applied on the whole layers' output and not on each element of output layer individually.

– today
Nov 15 '18 at 13:27














ok so Sequential() cannot have more than one output layer right?

– Corse
Nov 15 '18 at 14:21





ok so Sequential() cannot have more than one output layer right?

– Corse
Nov 15 '18 at 14:21




1




1





That's right. You need to use functional API instead if you want more flexibility.

– today
Nov 15 '18 at 14:24





That's right. You need to use functional API instead if you want more flexibility.

– today
Nov 15 '18 at 14:24













alright, thank you!

– Corse
Nov 15 '18 at 14:36





alright, thank you!

– Corse
Nov 15 '18 at 14:36












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53320451%2fregarding-loss-weighting-in-keras-regression-problem-for-multiple-outputs%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53320451%2fregarding-loss-weighting-in-keras-regression-problem-for-multiple-outputs%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto