How to compute Receiving Operating Characteristic (ROC) and AUC in keras?

前端 未结 8 1819
一生所求
一生所求 2020-11-28 02:07

I have a multi output(200) binary classification model which I wrote in keras.

In this model I want to add additional metrics such as ROC and AUC but to my knowledg

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 02:45

    You can monitor auc during training by providing metrics the following way:

    METRICS = [
          keras.metrics.TruePositives(name='tp'),
          keras.metrics.FalsePositives(name='fp'),
          keras.metrics.TrueNegatives(name='tn'),
          keras.metrics.FalseNegatives(name='fn'), 
          keras.metrics.BinaryAccuracy(name='accuracy'),
          keras.metrics.Precision(name='precision'),
          keras.metrics.Recall(name='recall'),
          keras.metrics.AUC(name='auc'),
    ]
    
    
    model = keras.Sequential([
        keras.layers.Dense(16, activation='relu', input_shape=(train_features.shape[-1],)),
        keras.layers.Dense(1, activation='sigmoid'),
      ])
    
    model.compile(
        optimizer=keras.optimizers.Adam(lr=1e-3)
        loss=keras.losses.BinaryCrossentropy(),
        metrics=METRICS)
    
    

    for a more detailed tutorial see:
    https://www.tensorflow.org/tutorials/structured_data/imbalanced_data

提交回复
热议问题