简体   繁体   English

可以传递给 tf.keras.model.compile 的指标列表

[英]List of metrics that can be passed to tf.keras.model.compile

Based on the tensorflow documentation , when compiling a model, I can specify one or more metrics to use, such as 'accuracy' and 'mse'.根据tensorflow 文档,在编译模型时,我可以指定一个或多个要使用的指标,例如“准确度”和“mse”。 However, the documentation doesn't say what metrics are available.但是,文档没有说明可用的指标。 I tried to replace 'accuracy' with a few other classical metrics such as 'recall' or 'auc', but that didn't work.我尝试用其他一些经典指标(例如“召回”或“auc”)替换“准确度”,但这不起作用。

model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['recall'])

What metrics are available?有哪些指标可用? Where can I find a list of all the metrics keywords I can use?在哪里可以找到我可以使用的所有指标关键字的列表?

You have the following (usually with relation to a classification task)您有以下内容(通常与分类任务有关)

  1. Accuracy via:精度通过:

     keras.metrics.accuracy(y_true, y_pred)
  2. Binary Accuracy given a certain thershold:给定某个阈值的二进制精度

     keras.metrics.binary_accuracy(y_true, y_pred, threshold=0.5)
  3. Categorical Accuracy via:分类准确度通过:

     keras.metrics.categorical_accuracy(y_true, y_pred)
  4. Sparse Categorical Accuracy via:稀疏分类精度通过:

     keras.metrics.sparse_categorical_accuracy(y_true, y_pred)
  5. Sparse Categorical Accuracy given a certain k:给定 k 的稀疏分类精度

     keras.metrics.top_k_categorical_accuracy(y_true, y_pred, k=5)
  6. Sparse Categorical Accuracy given a certain k:给定 k 的稀疏分类精度

     keras.metrics.top_k_categorical_accuracy(y_true, y_pred, k=5)
  7. Cosine Proximity given a certain axis:给定某个轴的余弦接近度

     keras.metrics.cosine_proximity(y_true, y_pred, axis=-1)

In addition to the metrics above, you may use any of the loss functions described in the loss function page as metrics.除了上述的指标,则可以使用任何的在损失函数页面作为度量描述的损失函数。 You may also implement your own custom metric, for example:您还可以实现自己的自定义指标,例如:

import keras.backend as K

def mean_pred(y_true, y_pred):
    return K.mean(y_pred)

model.compile(optimizer='rmsprop',
              loss='binary_crossentropy',
              metrics=['accuracy', mean_pred])

Reference: Keras Metrics , Keras Loss Functions参考: Keras 指标Keras 损失函数

尝试使用此处的指标之一: https : //keras.io/metrics/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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