Category: 06. Metrics

  • Metric wrappers and reduction metrics

    MeanMetricWrapper class Wrap a stateless metric function with the Mean metric. You could use this class to quickly build a mean metric from a function. The function needs to have the signature fn(y_true, y_pred) and return a per-sample loss array. MeanMetricWrapper.result() will return the average metric value across all samples seen so far. For example: Arguments Mean class Compute the (weighted) mean of…

  • Hinge metrics for “maximum-margin” classification

    Hinge class Computes the hinge metric between y_true and y_pred. y_true values are expected to be -1 or 1. If binary (0 or 1) labels are provided we will convert them to -1 or 1. Arguments Examples SquaredHinge class Computes the hinge metric between y_true and y_pred. y_true values are expected to be -1 or 1. If binary (0 or 1) labels are provided we…

  • Image segmentation metrics

    IoU class Computes the Intersection-Over-Union metric for specific target classes. Formula: Intersection-Over-Union is a common evaluation metric for semantic image segmentation. To compute IoUs, the predictions are accumulated in a confusion matrix, weighted by sample_weight and the metric is then calculated from it. If sample_weight is None, weights default to 1. Use sample_weight of 0 to mask values. Note, this class first computes…

  • Classification metrics based on True/False positives & negatives

    AUC class Approximates the AUC (Area under the curve) of the ROC or PR curves. The AUC (Area under the curve) of the ROC (Receiver operating characteristic; default) or PR (Precision Recall) curves are quality measures of binary classifiers. Unlike the accuracy, and like cross-entropy losses, ROC-AUC and PR-AUC evaluate all the operational points of a…

  • Regression metrics

    MeanSquaredError class Computes the mean squared error between y_true and y_pred. Formula: Arguments Example RootMeanSquaredError class Computes root mean squared error metric between y_true and y_pred. Formula: Arguments Example Example Usage with compile() API: MeanAbsoluteError class Computes the mean absolute error between the labels and predictions. Formula: Arguments Examples Usage with compile() API: MeanAbsolutePercentageError class Computes mean absolute percentage error between y_true and y_pred. Formula: Arguments Example Example Usage with compile() API: MeanSquaredLogarithmicError class Computes…

  • Probabilistic metrics

    BinaryCrossentropy class Computes the crossentropy metric between the labels and predictions. This is the crossentropy metric class to be used when there are only two label classes (0 and 1). Arguments Example Example Usage with compile() API: CategoricalCrossentropy class Computes the crossentropy metric between the labels and predictions. This is the crossentropy metric class to be used when there…

  • Accuracy metrics

    Accuracy class Calculates how often predictions equal labels. This metric creates two local variables, total and count that are used to compute the frequency with which y_pred matches y_true. This frequency is ultimately returned as binary accuracy: an idempotent operation that simply divides total by count. If sample_weight is None, weights default to 1. Use sample_weight of 0 to mask values. Arguments Examples Usage with compile() API: BinaryAccuracy class Calculates how often predictions match binary…

  • Base Metric class

    Metric class Encapsulates metric logic and state. Arguments Example Usage with compile() API: To be implemented by subclasses: Example subclass implementation: