Skip to content

Commit

Permalink
WIP utility singleLabelConfusionMatrix(List<Prediction<MultiLabel>> p…
Browse files Browse the repository at this point in the history
…redictions)

- partially represent false negatives by calling them false positives tied to some predicted label if there is one
  • Loading branch information
nezda committed Apr 22, 2021
1 parent 35735aa commit b5b1206
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -125,7 +126,7 @@ public static List<Prediction<Label>> mkSingleLabelPredictions(List<Prediction<M
// intersection(trueLabels, predicted) = true positives
// predicted - trueLabels = false positives
// trueLabels - predicted = false negatives
return predicted.stream().map(pred -> {
return Stream.concat(predicted.stream().map(pred -> {
if (trueLabels.contains(pred)) {
return mkPrediction(pred.getLabel(), pred.getLabel());
} else if (trueLabels.size() == 1) {
Expand All @@ -134,7 +135,19 @@ public static List<Prediction<Label>> mkSingleLabelPredictions(List<Prediction<M
// arbitrarily pick first trueLabel
return mkPrediction(trueLabels.iterator().next().getLabel(), pred.getLabel());
}
});
}),
// partially represent false negatives by calling them false positives tied to some predicted label if there is one
trueLabels.stream().filter(t -> !predicted.contains(t)).flatMap(fnTrueLabel -> {
if (predicted.isEmpty()) {
// nothing to pin this on
return Stream.of();
} else if (predicted.size() == 1) {
return Stream.of(mkPrediction(fnTrueLabel.getLabel(), predicted.iterator().next().getLabel()));
} else {
// arbitrarily pick first predicted label
return Stream.of(mkPrediction(fnTrueLabel.getLabel(), predicted.iterator().next().getLabel()));
}
}));
}).collect(Collectors.toList());
}

Expand Down

0 comments on commit b5b1206

Please sign in to comment.