I have a list of objects of Statistic class. It contains following attributes:
private String name;
private double min;
private double max;
private double avg;
private double stDev;
private double variation;
private double skewness;
private double median;
private double q1;
private double q3;
private double sum;
private int count;
During the runtime of a program they are calculated and at the end I want to create a list of 5 best results judging by the accuracy value. My code is as follows:
String filePath = "src/test/resources/json/test_write_to_file.json";
SimulationOption option = JsonUtil.read(filePath);
MainController mainController = new MainController();
List<CrossValidationResult> results = mainController.start(option);
int N = 5;
List<Statistic> testingStatistics = ClassificationStatisticHelper.calculateClassificationResultsStatistics(results
.parallelStream()
.map(CrossValidationResult::getTestingResults)
.sorted(Comparator.comparingDouble(o->o.getClassificationCharacteristic().getAccuracy()).reversed())
.limit(N)
.collect(Collectors.toList()));
I'm getting an error "Cannot resolve method 'getClassificationCharacteristic' in 'Object'" at "getClassificationCharacteristic()" part. This error disappears if I delete ".reversed" but then I get bottom N not top N results. Obviously it's the wrong way of doing what I wanted to do. How should I go about fixing this?
EDIT:
List<Statistic> testingStatistics = ClassificationStatisticHelper.calculateClassificationResultsStatistics(results
.parallelStream()
.map(CrossValidationResult::getTestingResults)
.sorted(Comparator.reverseOrder().thenComparingDouble(o->o.getClassificationCharacteristic().getAccuracy()))
.limit(N)
.collect(Collectors.toList()));
Doesn't work as well
EDIT 2: getClassificationCharacteristic().getAccuracy() comes from com.common.metrics.ClassificationCharacteristic. Here is how it's calculated:
private void calculateAccuracy() {
int correctSum = 0;
for (int i = 0; i < classes.length; i++) {
correctSum += matrix[i][i];
}
int instances = classActualSupport.values().parallelStream().reduce(Integer::sum).orElse(0);
this.accuracy = 1d * correctSum / instances;
}
Hope it's relevant to the problem.