-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathUCRClassificationTest.java
97 lines (81 loc) · 3.55 KB
/
UCRClassificationTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (c) 2016 - Patrick Schäfer ([email protected])
// Distributed under the GLP 3.0 (See accompanying file LICENSE)
package sfa;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import sfa.classification.*;
import sfa.timeseries.TimeSeries;
import sfa.timeseries.TimeSeriesLoader;
import java.io.File;
import java.io.IOException;
@RunWith(JUnit4.class)
public class UCRClassificationTest {
// The datasets to use
public static String[] datasets = new String[]{
"Coffee", "Beef", "CBF",
"ECG200",
"FaceFour", "OliveOil",
"Gun_Point",
"DiatomSizeReduction",
"ECGFiveDays",
"TwoLeadECG",
"SonyAIBORobotSurfaceII",
"MoteStrain",
"ItalyPowerDemand",
"SonyAIBORobotSurface",
};
@Test
public void testUCRClassification() throws IOException {
// the relative path to the datasets
ClassLoader classLoader = SFAWordsTest.class.getClassLoader();
File dir = new File(classLoader.getResource("datasets/univariate/").getFile());
//File dir = new File("/Users/bzcschae/workspace/similarity/datasets/classification");
for (String s : datasets) {
File d = new File(dir.getAbsolutePath() + "/" + s);
if (d.exists() && d.isDirectory()) {
for (File train : d.listFiles()) {
if (train.getName().toUpperCase().endsWith("TRAIN")) {
File test = new File(train.getAbsolutePath().replaceFirst("TRAIN", "TEST"));
if (!test.exists()) {
System.err.println("File " + test.getName() + " does not exist");
test = null;
}
Classifier.DEBUG = false;
// Load the train/test splits
TimeSeries[] testSamples = TimeSeriesLoader.loadDataset(test);
TimeSeries[] trainSamples = TimeSeriesLoader.loadDataset(train);
// The WEASEL-classifier
Classifier w = new WEASELClassifier();
Classifier.Score scoreW = w.eval(trainSamples, testSamples);
System.out.println(s + ";" + scoreW.toString());
// The BOSS ensemble classifier
Classifier boss = new BOSSEnsembleClassifier();
Classifier.Score scoreBOSS = boss.eval(trainSamples, testSamples);
System.out.println(s + ";" + scoreBOSS.toString());
// The BOSS VS classifier
Classifier bossVS = new BOSSVSClassifier();
Classifier.Score scoreBOSSVS = bossVS.eval(trainSamples, testSamples);
System.out.println(s + ";" + scoreBOSSVS.toString());
// The Shotgun ensemble classifier
Classifier shotgunEnsemble = new ShotgunEnsembleClassifier();
Classifier.Score scoreShotgunEnsemble = shotgunEnsemble.eval(trainSamples, testSamples);
System.out.println(s + ";" + scoreShotgunEnsemble.toString());
// The Shotgun classifier
Classifier shotgun = new ShotgunClassifier();
Classifier.Score scoreShotgun = shotgun.eval(trainSamples, testSamples);
System.out.println(s + ";" + scoreShotgun.toString());
}
}
} else {
// not really an error. just a hint:
System.out.println("Dataset could not be found: " + d.getAbsolutePath() + ". " +
"Please download datasets from [http://www.cs.ucr.edu/~eamonn/time_series_data/].");
}
}
}
public static void main(String[] args) throws IOException {
UCRClassificationTest ucr = new UCRClassificationTest();
ucr.testUCRClassification();
}
}