Validation for Matthews
@@ -35,6 +35,9 @@ class Correlation(Metric):
def __call__(self, predictions, labels):
""" Accumulate statistics for a set of predictions and labels.
+ Values depend on correlation type; for Matthews we enforce that labels
+ are binary {0,1} (for now).
+
Args:
predictions: Tensor or np.array
labels: Tensor or np.array of same shape as predictions
@@ -51,6 +54,12 @@ class Correlation(Metric):
" preds=%s, labels=%s" % (
str(predictions.shape),
str(labels.shape)))
+ # Validate Matthews, must be binary labels.
+ if self.corr_type == 'matthews':
+ _validate_binary = lambda t: np.all((t == 0) | (t == 1))
+ assert _validate_binary(predictions)
+ assert _validate_binary(labels)
+
predictions = list(predictions.flatten())
labels = list(labels.flatten())
