批平均和全局 Fscore 之间的区别

Difference between batch-average and global Fscore

我面临一个减少误报的问题,正负大小的比例约为。 1.7:1。 我从 中了解到,使用精度、召回率、FScore,甚至根据成本对真阳性、假阳性、真阴性和假阴性进行不同的加权来评估不同的模型来处理指定的分类任务。

Precision, Recall, and FScore are removed from keras, I found some methods to do the tracking of those metrics during training, such as github repo keras-metrics.

此外,我还通过这样定义精度找到了其他解决方案,

def precision(y_true, y_pred):
    """Precision metric.
    Only computes a batch-wise average of precision.
    Computes the precision, a metric for multi-label classification of
    how many selected items are relevant.
    """
    true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
    predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))
    precision = true_positives / (predicted_positives + K.epsilon())
    return precision

但是,由于这些方法在训练期间跟踪指标,因此所有这些方法都声称是 batch-wise average 而不是全局值。 我想知道在训练期间跟踪这些指标有多大必要。或者我在训练期间只关注 lossaccuracy,并使用 scikit-learn 等验证函数评估所有模型,以将这些指标与全局方法进行比较。

在 Keras 中,所有训练指标都是按批次测量的。 为了获得全局指标,Keras 将对这些批量指标进行平均。

类似于 sum(batch_metrics) / batches

考虑到 "number of samples",由于大多数指标都是平均值,因此进行这种平均不会对全局值产生太大影响。

如果samples % batch_size == 0,那么我们可以说:

sum(all_samples_metrics) / samples == sum(all_batch_metrics) / batches

但是你说的这些具体指标不是除以"number of samples",而是除以样本数"that satisfy a condition"。因此,每批中的除数是不同的。从数学上讲,对批量指标进行平均以获得全局结果的结果不会反映真实的全局结果。

那么,我们能说它们不适合训练吗?

嗯,不。它们可能适合训练。有时 "accuracy" 是特定问题的糟糕指标。

批量使用这些指标的关键是要有足够大的批量大小,以避免因数变化太大。