Если вам нужна дополнительная информация, я привел ссылку на документацию tenorflow. Я надеюсь, что это помогает. :-)
ел бы реализовать пользовательскую метрику в керасах, которая вычисляет отзыв, предполагая, что верхний k% наиболее вероятенy_pred_probs
это правда.
Вnumpy
Я бы сделал это следующим образом. Сортировка y_preds_probs. Затем возьмите значение наk
Индекс Записьk=0.5
дал бы среднее значение.
kth_pos = int(k * len(y_pred_probs))
threshold = np.sort(y_pred_probs)[::-1][kth_pos]
y_pred = np.asarra,y([1 if i >= threshold else 0 for i in y_pred_probs])
Ответ от:Керас пользовательский порог решения для точности и отзыва довольно близко, но предполагает, что порог для принятия решения о том, какойy_pred
Предполагается, что истина уже известна. Я хотел бы объединить подходы и реализовать поиск threshold_value на основеk
а такжеy_pred
в бэкэнде в Керасе, если это возможно.
def recall_at_k(y_true, y_pred):
"""Recall metric.
Computes the recall over the whole batch using threshold_value from k-th percentile.
"""
###
threshold_value = # calculate value of k-th percentile of y_pred here
###
# Adaptation of the "round()" used before to get the predictions. Clipping to make sure that the predicted raw values are between 0 and 1.
y_pred = K.cast(K.greater(K.clip(y_pred, 0, 1), threshold_value), K.floatx())
# Compute the number of true positives. Rounding in prevention to make sure we have an integer.
true_positives = K.round(K.sum(K.clip(y_true * y_pred, 0, 1)))
# Compute the number of positive targets.
possible_positives = K.sum(K.clip(y_true, 0, 1))
recall_ratio = true_positives / (possible_positives + K.epsilon())
return recall_ratio