Metric¶
This module includes a set of metric classes for evaluating the model’s performance. The specific metric classes could be converted from C++ implmentation or implemented directly using Python.
Example usage:
from singa import tensor
from singa import metric
x = tensor.Tensor((3, 5))
x.uniform(0, 1) # randomly genearte the prediction activation
x = tensor.SoftMax(x) # normalize the prediction into probabilities
y = tensor.from_numpy(np.array([0, 1, 3], dtype=np.int)) # set the truth
f = metric.Accuracy()
acc = f.evaluate(x, y) # averaged accuracy over all 3 samples in x
-
class
singa.metric.
Metric
¶ Bases:
object
Base metric class.
Subclasses that wrap the C++ loss classes can use the inherited foward, and evaluate functions of this base class. Other subclasses need to override these functions. Users need to feed in the predictions and ground truth to get the metric values.
-
forward
(x, y)¶ Compute the metric for each sample.
-
-
class
singa.metric.
Accuracy
¶ Bases:
singa.metric.Metric
Compute the top one accuracy for single label prediction tasks.
It calls the C++ functions to do the calculation.
-
class
singa.metric.
Precision
(top_k)¶ Bases:
singa.metric.Metric
Make the top-k labels of max probability as the prediction
Compute the precision against the groundtruth labels
-
forward
(x, y)¶ Compute the precision for each sample.
Convert tensor to numpy for computation
-
-
class
singa.metric.
Recall
(top_k)¶ Bases:
singa.metric.Metric
Make the top-k labels of max probability as the prediction
Compute the recall against the groundtruth labels
-
forward
(x, y)¶ Compute the recall for each sample.
Convert tensor to numpy for computation
-