Compute precision / recall in binary classification, given the prediction vector and the label vector.
| 178 | |
| 179 | |
| 180 | class BinaryClassificationStats(Inferencer): |
| 181 | """ |
| 182 | Compute precision / recall in binary classification, given the |
| 183 | prediction vector and the label vector. |
| 184 | """ |
| 185 | |
| 186 | def __init__(self, pred_tensor_name, label_tensor_name, prefix='val'): |
| 187 | """ |
| 188 | Args: |
| 189 | pred_tensor_name(str): name of the 0/1 prediction tensor. |
| 190 | label_tensor_name(str): name of the 0/1 label tensor. |
| 191 | """ |
| 192 | self.pred_tensor_name = pred_tensor_name |
| 193 | self.label_tensor_name = label_tensor_name |
| 194 | self.prefix = prefix |
| 195 | |
| 196 | def _before_inference(self): |
| 197 | self.stat = BinaryStatistics() |
| 198 | |
| 199 | def _get_fetches(self): |
| 200 | return [self.pred_tensor_name, self.label_tensor_name] |
| 201 | |
| 202 | def _on_fetches(self, outputs): |
| 203 | pred, label = outputs |
| 204 | self.stat.feed(pred, label) |
| 205 | |
| 206 | def _after_inference(self): |
| 207 | return {self.prefix + '_precision': self.stat.precision, |
| 208 | self.prefix + '_recall': self.stat.recall} |
no outgoing calls
no test coverage detected
searching dependent graphs…