简体   繁体   中英

How to define an spesific loss function for keras LSTM model

Ive just started learning machine learning using python with Keras and I have recently created a basic LSTM RNN.

My question is if it is possible to define a function error myself without having to specifie the target data.

In the basic model I created, I gave the input data and the corresponding target data for training, specifying which function error to use, like "meansquarederror".

My question is if it is possible to define a model in keras in which only the inputs, and a custom function error that would take the output of the NN to calculate an error (completly new metric), where given for training the NN.

What I want is to calculate the error of each input in predicting the outputs with a custom function.

Is that possible?

Ok ive found it is much easier than I thought.

def custom_loss(y_true, y_pred):
            
    # calculate loss, using y_pred
        
    return loss
  
model.compile(loss=custom_loss, optimizer='adam')

Its done just like that

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM