From f1e8ce8eefc73af71940e775947fd80042b878bd Mon Sep 17 00:00:00 2001 From: acsolle66 Date: Wed, 11 Oct 2023 11:43:13 +0200 Subject: [PATCH] Final cleanup in files Went trough the files once more time to remove remaining one-line comments Didn't removed the comment from the benchmark on line 107 I think it is useful. --- example/src/main/java/de/example/benchmark/Benchmark.java | 1 - .../java/de/example/data/seaborn/SeabornDataProcessor.java | 4 ++-- example/src/main/java/de/example/knn/KnnIrisExample.java | 2 +- example/src/main/java/de/example/knn/KnnSeabornExample.java | 4 ++-- lib/src/main/java/de/edux/data/reader/CSVIDataReader.java | 2 +- lib/src/main/java/de/edux/ml/randomforest/RandomForest.java | 1 - .../test/java/de/edux/data/provider/DataProcessorTest.java | 1 - .../test/java/de/edux/data/provider/SeabornDataProcessor.java | 4 ++-- 8 files changed, 8 insertions(+), 11 deletions(-) diff --git a/example/src/main/java/de/example/benchmark/Benchmark.java b/example/src/main/java/de/example/benchmark/Benchmark.java index 2f3fcc7..fb93600 100644 --- a/example/src/main/java/de/example/benchmark/Benchmark.java +++ b/example/src/main/java/de/example/benchmark/Benchmark.java @@ -90,7 +90,6 @@ private void run() { }); - //Sort and print results with numeration begin with best average accuracy System.out.println("Classifier performances (sorted by average accuracy):"); results.entrySet().stream() .map(entry -> { diff --git a/example/src/main/java/de/example/data/seaborn/SeabornDataProcessor.java b/example/src/main/java/de/example/data/seaborn/SeabornDataProcessor.java index 124b6f3..376767e 100644 --- a/example/src/main/java/de/example/data/seaborn/SeabornDataProcessor.java +++ b/example/src/main/java/de/example/data/seaborn/SeabornDataProcessor.java @@ -145,7 +145,7 @@ public double[][] getTestLabels() { } private double[][] featuresOf(List data) { - double[][] features = new double[data.size()][4]; // 4 numerische Eigenschaften + double[][] features = new double[data.size()][4]; for (int i = 0; i < data.size(); i++) { Penguin p = data.get(i); @@ -159,7 +159,7 @@ private double[][] featuresOf(List data) { } private double[][] labelsOf(List data) { - double[][] labels = new double[data.size()][3]; // 3 Pinguinarten + double[][] labels = new double[data.size()][3]; for (int i = 0; i < data.size(); i++) { Penguin p = data.get(i); diff --git a/example/src/main/java/de/example/knn/KnnIrisExample.java b/example/src/main/java/de/example/knn/KnnIrisExample.java index 0e5d536..e4d1850 100644 --- a/example/src/main/java/de/example/knn/KnnIrisExample.java +++ b/example/src/main/java/de/example/knn/KnnIrisExample.java @@ -27,7 +27,7 @@ public static void main(String[] args) { irisDataProcessor.split(data, TRAIN_TEST_SPLIT_RATIO); Classifier knn = new KnnClassifier(2); - //Train and evaluate + knn.train(irisDataProcessor.getTrainFeatures(), irisDataProcessor.getTrainLabels()); knn.evaluate(irisDataProcessor.getTestFeatures(), irisDataProcessor.getTestLabels()); } diff --git a/example/src/main/java/de/example/knn/KnnSeabornExample.java b/example/src/main/java/de/example/knn/KnnSeabornExample.java index d647908..324d438 100644 --- a/example/src/main/java/de/example/knn/KnnSeabornExample.java +++ b/example/src/main/java/de/example/knn/KnnSeabornExample.java @@ -22,13 +22,13 @@ public class KnnSeabornExample { private static final File CSV_FILE = new File("example" + File.separator + "datasets" + File.separator + "seaborn-penguins" + File.separator + "penguins.csv"); public static void main(String[] args) { - //Load Data, shuffle, normalize, filter incomplete records out. var seabornDataProcessor = new SeabornDataProcessor(); List data = seabornDataProcessor.loadDataSetFromCSV(CSV_FILE, ',', SHUFFLE, NORMALIZE, FILTER_INCOMPLETE_RECORDS); - //Split dataset into train and test + Dataset dataset = seabornDataProcessor.split(data, TRAIN_TEST_SPLIT_RATIO); var seabornProvider = new SeabornProvider(data, dataset.trainData(), dataset.testData()); seabornProvider.printStatistics(); + Classifier knn = new KnnClassifier(2); knn.train(seabornProvider.getTrainFeatures(), seabornProvider.getTrainLabels()); knn.evaluate(seabornProvider.getTestFeatures(), seabornProvider.getTestLabels()); diff --git a/lib/src/main/java/de/edux/data/reader/CSVIDataReader.java b/lib/src/main/java/de/edux/data/reader/CSVIDataReader.java index 2e8882c..6b14067 100644 --- a/lib/src/main/java/de/edux/data/reader/CSVIDataReader.java +++ b/lib/src/main/java/de/edux/data/reader/CSVIDataReader.java @@ -14,7 +14,7 @@ public class CSVIDataReader implements IDataReader { public List readFile(File file, char separator) { - CSVParser customCSVParser = new CSVParserBuilder().withSeparator(separator).build(); // custom separator + CSVParser customCSVParser = new CSVParserBuilder().withSeparator(separator).build(); List result; try(CSVReader reader = new CSVReaderBuilder( new FileReader(file)) diff --git a/lib/src/main/java/de/edux/ml/randomforest/RandomForest.java b/lib/src/main/java/de/edux/ml/randomforest/RandomForest.java index bf1e55f..e4c29b2 100644 --- a/lib/src/main/java/de/edux/ml/randomforest/RandomForest.java +++ b/lib/src/main/java/de/edux/ml/randomforest/RandomForest.java @@ -129,7 +129,6 @@ public double[] predict(double[] feature) { for (Future future : futures) { try { double[] prediction = future.get(); - /* voteMap.merge(prediction, 1L, Long::sum);*/ double label = getIndexOfHighestValue(prediction); voteMap.merge(label, 1L, Long::sum); } catch (InterruptedException | ExecutionException e) { diff --git a/lib/src/test/java/de/edux/data/provider/DataProcessorTest.java b/lib/src/test/java/de/edux/data/provider/DataProcessorTest.java index f0c36f3..a0b3af0 100644 --- a/lib/src/test/java/de/edux/data/provider/DataProcessorTest.java +++ b/lib/src/test/java/de/edux/data/provider/DataProcessorTest.java @@ -105,7 +105,6 @@ private DataProcessor getDummyDataUtil() { @Override public void normalize(List dataset) { - // Mock normalize for the sake of testing } @Override diff --git a/lib/src/test/java/de/edux/data/provider/SeabornDataProcessor.java b/lib/src/test/java/de/edux/data/provider/SeabornDataProcessor.java index 0584568..bc08ee8 100644 --- a/lib/src/test/java/de/edux/data/provider/SeabornDataProcessor.java +++ b/lib/src/test/java/de/edux/data/provider/SeabornDataProcessor.java @@ -143,7 +143,7 @@ public double[][] getTestLabels() { } private double[][] featuresOf(List data) { - double[][] features = new double[data.size()][4]; // 4 numerische Eigenschaften + double[][] features = new double[data.size()][4]; for (int i = 0; i < data.size(); i++) { Penguin p = data.get(i); @@ -157,7 +157,7 @@ private double[][] featuresOf(List data) { } private double[][] labelsOf(List data) { - double[][] labels = new double[data.size()][3]; // 3 Pinguinarten + double[][] labels = new double[data.size()][3]; for (int i = 0; i < data.size(); i++) { Penguin p = data.get(i);