Hi,
Does tf.keras.metrics.AUC work for sparse multi-class classification or do I need to transform labels into one-hot representation?
Thanks!
Fadi
lgusm
March 14, 2022, 11:20am
3
Maybe @markdaoust can help
A quick experiment and scan of the code says no.
y_true goes straight here:
For estimation of these metrics over a stream of data, the function creates an
`update_op` operation that updates the given variables.
If `sample_weight` is `None`, weights default to 1.
Use weights of 0 to mask values.
Args:
variables_to_update: Dictionary with 'tp', 'fn', 'tn', 'fp' as valid keys
and corresponding variables to update as values.
y_true: A `Tensor` whose shape matches `y_pred`. Will be cast to `bool`.
y_pred: A floating point `Tensor` of arbitrary shape and whose values are in
the range `[0, 1]`.
thresholds: A float value, float tensor, python list, or tuple of float
thresholds in `[0, 1]`, or NEG_INF (used when top_k is set).
top_k: Optional int, indicates that the positive labels should be limited to
the top k predictions.
class_id: Optional int, limits the prediction and labels to the class
specified by this argument.
sample_weight: Optional `Tensor` whose rank is either 0, or the same rank as
`y_true`, and must be broadcastable to `y_true` (i.e., all dimensions must
It’s easy to write a wrapper to do the one-hot.
If you’re motivated to make this work you could always ask on the keras repo if they’d accept a “sparse” Argument to the constructor (or code to do the one-hot if passed an int).
2 Likes
Thanks @markdaoust & @lgusm . I will check the code.
Meanwhile I had transformed everything into non-sparse but your point of view of adding a wrapper is better I guess.
1 Like