torcheval.metrics.ClickThroughRate¶
-
class
torcheval.metrics.
ClickThroughRate
(*, num_tasks: int = 1, device: Optional[device] = None)[source]¶ Compute the click through rate given click events. Its functional version is
torcheval.metrics.functional.click_through_rate
.Parameters: num_tasks (int) – Number of tasks that need weighted_calibration calculation. Default value is 1. Examples:
>>> import torch >>> from torcheval.metrics.ranking import ClickThroughRate >>> metric = ClickThroughRate() >>> input = torch.tensor([0, 1, 0, 1, 1, 0, 0, 1]) >>> metric.update(input) >>> metric.compute() tensor([0.5]) >>> metric = ClickThroughRate() >>> weights = torch.tensor([1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 1.0, 2.0]) >>> metric.update(input, weights) >>> metric.compute() tensor([0.58333]) >>> metric = ClickThroughRate(num_tasks=2) >>> input = torch.tensor([[0, 1, 0, 1], [1, 0, 0, 1]]) >>> weights = torch.tensor([[1.0, 2.0, 1.0, 2.0],[1.0, 2.0, 1.0, 1.0]]) >>> metric.update(input, weights) >>> metric.compute() tensor([0.6667, 0.4])
-
__init__
(*, num_tasks: int = 1, device: Optional[device] = None) None [source]¶ Initialize a metric object and its internal states.
Use
self._add_state()
to initialize state variables of your metric class. The state variables should be eithertorch.Tensor
, a list oftorch.Tensor
, or a dictionary withtorch.Tensor
as values
Methods
__init__
(*[, num_tasks, device])Initialize a metric object and its internal states. compute
()Return the stacked click through rank scores. load_state_dict
(state_dict[, strict])Loads metric state variables from state_dict. merge_state
(metrics)Merge the metric state with its counterparts from other metric instances. reset
()Reset the metric state variables to their default value. state_dict
()Save metric state variables in state_dict. to
(device, *args, **kwargs)Move tensors in metric state variables to device. update
(input[, weights])Update the metric state with new inputs. Attributes
device
The last input device of Metric.to()
.-