# NOT RUN {
# multi-class hamming loss
hl = loss_hamming(mode='multiclass', threshold=0.6)
actuals = tf$constant(list(as.integer(c(1, 0, 0, 0)),as.integer(c(0, 0, 1, 0)),
as.integer(c(0, 0, 0, 1)),as.integer(c(0, 1, 0, 0))),
dtype=tf$float32)
predictions = tf$constant(list(c(0.8, 0.1, 0.1, 0),
c(0.2, 0, 0.8, 0),
c(0.05, 0.05, 0.1, 0.8),
c(1, 0, 0, 0)),
dtype=tf$float32)
hl$update_state(actuals, predictions)
paste('Hamming loss: ', hl$result()$numpy()) # 0.25
# multi-label hamming loss
hl = loss_hamming(mode='multilabel', threshold=0.8)
actuals = tf$constant(list(as.integer(c(1, 0, 1, 0)),as.integer(c(0, 1, 0, 1)),
as.integer(c(0, 0, 0,1))), dtype=tf$int32)
predictions = tf$constant(list(c(0.82, 0.5, 0.90, 0),
c(0, 1, 0.4, 0.98),
c(0.89, 0.79, 0, 0.3)),
dtype=tf$float32)
hl$update_state(actuals, predictions)
paste('Hamming loss: ', hl$result()$numpy()) # 0.16666667
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab