How to calculate precision and recall in Keras

后端 未结 5 590
别跟我提以往
别跟我提以往 2020-12-13 03:47

I am building a multi-class classifier with Keras 2.02 (with Tensorflow backend),and I do not know how to calculate precision and recall in Keras. Please help me.

5条回答
  •  囚心锁ツ
    2020-12-13 04:27

    Python package keras-metrics could be useful for this (I'm the package's author).

    import keras
    import keras_metrics
    
    model = models.Sequential()
    model.add(keras.layers.Dense(1, activation="sigmoid", input_dim=2))
    model.add(keras.layers.Dense(1, activation="softmax"))
    
    model.compile(optimizer="sgd",
                  loss="binary_crossentropy",
                  metrics=[keras_metrics.precision(), keras_metrics.recall()])
    

    UPDATE: Starting with Keras version 2.3.0, such metrics as precision, recall, etc. are provided within library distribution package.

    The usage is the following:

    model.compile(optimizer="sgd",
                  loss="binary_crossentropy",
                  metrics=[keras.metrics.Precision(), keras.metrics.Recall()])
    

提交回复
热议问题