Esempio n. 1
0
def zero_one_accuracy(y_true, y_pred):
    y_true, y_pred = tensorify(y_true), tensorify(y_pred)
    n_instances, n_objects = get_instances_objects(y_true)
    equal_ranks = K.cast(K.all(K.equal(y_pred, y_true), axis=1), dtype="float32")
    denominator = K.cast(n_instances, dtype="float32")
    zero_one_loss = K.sum(equal_ranks) / denominator
    return zero_one_loss
Esempio n. 2
0
def zero_one_accuracy_for_scores(y_true, y_pred):
    y_true, y_pred = tensorify(y_true), tensorify(y_pred)
    n_instances, n_objects = get_instances_objects(y_true)
    predicted_rankings = scores_to_rankings(n_objects, y_pred)
    y_true = K.cast(y_true, dtype='float32')
    equal_ranks = K.cast(K.all(K.equal(predicted_rankings, y_true), axis=1),
                         dtype='float32')
    denominator = K.cast(n_instances, dtype='float32')
    zero_one_loss = K.sum(equal_ranks) / denominator
    return zero_one_loss
Esempio n. 3
0
def spearman_correlation_for_scores(y_true, y_pred):
    y_true, y_pred = tensorify(y_true), tensorify(y_pred)
    n_instances, n_objects = get_instances_objects(y_true)
    predicted_rankings = scores_to_rankings(n_objects, y_pred)
    y_true = K.cast(y_true, dtype='float32')
    sum_of_squared_distances = tf.constant(0.0)
    for i in np.arange(K.int_shape(y_pred)[1]):
        objects_pred = predicted_rankings[:, i]
        objects_true = y_true[:, i]
        t = (objects_pred - objects_true)**2
        sum_of_squared_distances = sum_of_squared_distances + tf.reduce_sum(t)
    denominator = K.cast(n_objects * (n_objects**2 - 1) * n_instances,
                         dtype='float32')
    spearman_correlation = 1 - (6 * sum_of_squared_distances) / denominator
    return spearman_correlation