Calculates false negatives for recall@k. If `class_id` is specified, calculate binary true positives for `class_id` only. If `class_id` is not specified, calculate metrics for `k` predicted vs `n` label classes, where `n` is the 2nd dimension of `labels_sparse`. Args: labels:
(labels,
predictions_idx,
class_id=None,
weights=None)
| 2377 | |
| 2378 | |
| 2379 | def _sparse_false_negative_at_k(labels, |
| 2380 | predictions_idx, |
| 2381 | class_id=None, |
| 2382 | weights=None): |
| 2383 | """Calculates false negatives for recall@k. |
| 2384 | |
| 2385 | If `class_id` is specified, calculate binary true positives for `class_id` |
| 2386 | only. |
| 2387 | If `class_id` is not specified, calculate metrics for `k` predicted vs |
| 2388 | `n` label classes, where `n` is the 2nd dimension of `labels_sparse`. |
| 2389 | |
| 2390 | Args: |
| 2391 | labels: `int64` `Tensor` or `SparseTensor` with shape |
| 2392 | [D1, ... DN, num_labels], where N >= 1 and num_labels is the number of |
| 2393 | target classes for the associated prediction. Commonly, N=1 and `labels` |
| 2394 | has shape [batch_size, num_labels]. [D1, ... DN] must match |
| 2395 | `predictions_idx`. |
| 2396 | predictions_idx: 1-D or higher `int64` `Tensor` with last dimension `k`, |
| 2397 | top `k` predicted classes. For rank `n`, the first `n-1` dimensions must |
| 2398 | match `labels`. |
| 2399 | class_id: Class for which we want binary metrics. |
| 2400 | weights: `Tensor` whose rank is either 0, or n-1, where n is the rank of |
| 2401 | `labels`. If the latter, it must be broadcastable to `labels` (i.e., all |
| 2402 | dimensions must be either `1`, or the same as the corresponding `labels` |
| 2403 | dimension). |
| 2404 | |
| 2405 | Returns: |
| 2406 | A [D1, ... DN] `Tensor` of false negative counts. |
| 2407 | """ |
| 2408 | with ops.name_scope(None, 'false_negatives', |
| 2409 | (predictions_idx, labels, weights)): |
| 2410 | labels, predictions_idx = _maybe_select_class_id(labels, predictions_idx, |
| 2411 | class_id) |
| 2412 | fn = sets.set_size( |
| 2413 | sets.set_difference(predictions_idx, labels, aminusb=False)) |
| 2414 | fn = math_ops.cast(fn, dtypes.float64) |
| 2415 | if weights is not None: |
| 2416 | with ops.control_dependencies((weights_broadcast_ops.assert_broadcastable( |
| 2417 | weights, fn),)): |
| 2418 | weights = math_ops.cast(weights, dtypes.float64) |
| 2419 | fn = math_ops.multiply(fn, weights) |
| 2420 | return fn |
| 2421 | |
| 2422 | |
| 2423 | def _streaming_sparse_false_negative_at_k(labels, |
no test coverage detected