How to use single values of attributes within a custom loss function
up vote
0
down vote
favorite
I'm trying to build a neural network with Keras. Therefore, I need to implement a custom loss function that punishes a false prediction example based on another attribute from the example.
I don't really know if it is even possible to use single attribute values inside a custom loss function in keras.
Here is the header of my data set.
Ereignisart;KONTOPHASE;PRODUKTART;PRODUKT2;BAUSPAREINLAGE;BAUSPARSUMME;BEWERTUNGSZAHL;TREUEOPTIONSSTATUS;ZUTEILUNGSSTATUS;MEHRZUTEILUNG_BETRAG;SPARZINSSATZ;Marktzins;ZEITSCHEIBE;SALDO
The first attribute "Ereignisart" is the one I want to predict. With the last attribute "SALDO" I want to punish the prediction of "Ereignisart" weighted. I know how to write a custom loss function and give it the attribute "SALDO" ( i got this from here if someone is interested: https://datascience.stackexchange.com/questions/28440/custom-conditional-loss-function-in-keras) . But if I do it the way you can see below, every example of SALDO will be used and not only the given value of the example.content of SALDO in debugger
def customLoss(SALDO):
def loss(yTrue, yPred):
first_log=kBack.log(kBack.clip(yPred, kBack.epsilon(), None) + 1.)
second_log=kBack.log(kBack.clip(yTrue, kBack.epsilon(), None) + 1.)
return kBack.mean(kBack.square(first_log - "penalty dependent on SALDO" *second_log)), axis=-1)
return loss
In short, I guess I want to use the corresponding value of "SALDO" in my loss function for each pair of yTrue and yPred to punish a false prediction based on "SALDO".
tl;dr Is it possible to use single values of attributes in a custom Kears Loss function? If so, how?
Many thanks in advance
Fabian
python-2.7 tensorflow keras loss-function
New contributor
add a comment |
up vote
0
down vote
favorite
I'm trying to build a neural network with Keras. Therefore, I need to implement a custom loss function that punishes a false prediction example based on another attribute from the example.
I don't really know if it is even possible to use single attribute values inside a custom loss function in keras.
Here is the header of my data set.
Ereignisart;KONTOPHASE;PRODUKTART;PRODUKT2;BAUSPAREINLAGE;BAUSPARSUMME;BEWERTUNGSZAHL;TREUEOPTIONSSTATUS;ZUTEILUNGSSTATUS;MEHRZUTEILUNG_BETRAG;SPARZINSSATZ;Marktzins;ZEITSCHEIBE;SALDO
The first attribute "Ereignisart" is the one I want to predict. With the last attribute "SALDO" I want to punish the prediction of "Ereignisart" weighted. I know how to write a custom loss function and give it the attribute "SALDO" ( i got this from here if someone is interested: https://datascience.stackexchange.com/questions/28440/custom-conditional-loss-function-in-keras) . But if I do it the way you can see below, every example of SALDO will be used and not only the given value of the example.content of SALDO in debugger
def customLoss(SALDO):
def loss(yTrue, yPred):
first_log=kBack.log(kBack.clip(yPred, kBack.epsilon(), None) + 1.)
second_log=kBack.log(kBack.clip(yTrue, kBack.epsilon(), None) + 1.)
return kBack.mean(kBack.square(first_log - "penalty dependent on SALDO" *second_log)), axis=-1)
return loss
In short, I guess I want to use the corresponding value of "SALDO" in my loss function for each pair of yTrue and yPred to punish a false prediction based on "SALDO".
tl;dr Is it possible to use single values of attributes in a custom Kears Loss function? If so, how?
Many thanks in advance
Fabian
python-2.7 tensorflow keras loss-function
New contributor
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to build a neural network with Keras. Therefore, I need to implement a custom loss function that punishes a false prediction example based on another attribute from the example.
I don't really know if it is even possible to use single attribute values inside a custom loss function in keras.
Here is the header of my data set.
Ereignisart;KONTOPHASE;PRODUKTART;PRODUKT2;BAUSPAREINLAGE;BAUSPARSUMME;BEWERTUNGSZAHL;TREUEOPTIONSSTATUS;ZUTEILUNGSSTATUS;MEHRZUTEILUNG_BETRAG;SPARZINSSATZ;Marktzins;ZEITSCHEIBE;SALDO
The first attribute "Ereignisart" is the one I want to predict. With the last attribute "SALDO" I want to punish the prediction of "Ereignisart" weighted. I know how to write a custom loss function and give it the attribute "SALDO" ( i got this from here if someone is interested: https://datascience.stackexchange.com/questions/28440/custom-conditional-loss-function-in-keras) . But if I do it the way you can see below, every example of SALDO will be used and not only the given value of the example.content of SALDO in debugger
def customLoss(SALDO):
def loss(yTrue, yPred):
first_log=kBack.log(kBack.clip(yPred, kBack.epsilon(), None) + 1.)
second_log=kBack.log(kBack.clip(yTrue, kBack.epsilon(), None) + 1.)
return kBack.mean(kBack.square(first_log - "penalty dependent on SALDO" *second_log)), axis=-1)
return loss
In short, I guess I want to use the corresponding value of "SALDO" in my loss function for each pair of yTrue and yPred to punish a false prediction based on "SALDO".
tl;dr Is it possible to use single values of attributes in a custom Kears Loss function? If so, how?
Many thanks in advance
Fabian
python-2.7 tensorflow keras loss-function
New contributor
I'm trying to build a neural network with Keras. Therefore, I need to implement a custom loss function that punishes a false prediction example based on another attribute from the example.
I don't really know if it is even possible to use single attribute values inside a custom loss function in keras.
Here is the header of my data set.
Ereignisart;KONTOPHASE;PRODUKTART;PRODUKT2;BAUSPAREINLAGE;BAUSPARSUMME;BEWERTUNGSZAHL;TREUEOPTIONSSTATUS;ZUTEILUNGSSTATUS;MEHRZUTEILUNG_BETRAG;SPARZINSSATZ;Marktzins;ZEITSCHEIBE;SALDO
The first attribute "Ereignisart" is the one I want to predict. With the last attribute "SALDO" I want to punish the prediction of "Ereignisart" weighted. I know how to write a custom loss function and give it the attribute "SALDO" ( i got this from here if someone is interested: https://datascience.stackexchange.com/questions/28440/custom-conditional-loss-function-in-keras) . But if I do it the way you can see below, every example of SALDO will be used and not only the given value of the example.content of SALDO in debugger
def customLoss(SALDO):
def loss(yTrue, yPred):
first_log=kBack.log(kBack.clip(yPred, kBack.epsilon(), None) + 1.)
second_log=kBack.log(kBack.clip(yTrue, kBack.epsilon(), None) + 1.)
return kBack.mean(kBack.square(first_log - "penalty dependent on SALDO" *second_log)), axis=-1)
return loss
In short, I guess I want to use the corresponding value of "SALDO" in my loss function for each pair of yTrue and yPred to punish a false prediction based on "SALDO".
tl;dr Is it possible to use single values of attributes in a custom Kears Loss function? If so, how?
Many thanks in advance
Fabian
python-2.7 tensorflow keras loss-function
python-2.7 tensorflow keras loss-function
New contributor
New contributor
edited Nov 19 at 14:01
New contributor
asked Nov 19 at 13:19
Fabian
13
13
New contributor
New contributor
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Fabian is a new contributor. Be nice, and check out our Code of Conduct.
Fabian is a new contributor. Be nice, and check out our Code of Conduct.
Fabian is a new contributor. Be nice, and check out our Code of Conduct.
Fabian is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375512%2fhow-to-use-single-values-of-attributes-within-a-custom-loss-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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