Enhance test output
This commit is contained in:
@@ -19,9 +19,7 @@ public class App {
|
||||
static String path = "data/";
|
||||
static String datasetsFile = path + "datasets.txt";
|
||||
static String outputFile = "results_pbc4.txt";
|
||||
static boolean debug = true;
|
||||
static boolean stratify = false;
|
||||
static boolean normalizeData = false;
|
||||
static boolean debug = false;
|
||||
|
||||
public static void printAndExit(String s) {
|
||||
System.out.println(s);
|
||||
@@ -30,10 +28,8 @@ public class App {
|
||||
|
||||
private static Instances getInstances(String fileName) {
|
||||
DataSource source = null;
|
||||
System.out.println(String.format("Reading file " + path + "%s.arff", fileName));
|
||||
try {
|
||||
source = new DataSource(String.format(path + "%s.arff", fileName));
|
||||
System.out.println("File read.");
|
||||
return source.getDataSet();
|
||||
} catch (Exception e) {
|
||||
printAndExit(
|
||||
@@ -51,21 +47,12 @@ public class App {
|
||||
Instances instances;
|
||||
Instances training = null;
|
||||
Instances test = null;
|
||||
long startTime;
|
||||
// Normalize normalize = new Normalize();
|
||||
|
||||
// normalize.setInputFormat(instancesIn);
|
||||
// if (normalizeData) {
|
||||
// instances = Filter.useFilter(instancesIn, normalize);
|
||||
// } else {
|
||||
instances = instancesIn;
|
||||
// }
|
||||
instances.randomize(rand);
|
||||
if (stratify) {
|
||||
instances.stratify(numFolds);
|
||||
}
|
||||
instances.stratify(numFolds);
|
||||
for (int i = 0; i < numFolds; i++) {
|
||||
startTime = System.currentTimeMillis();
|
||||
long startTime = System.currentTimeMillis();
|
||||
training = instances.trainCV(numFolds, i);
|
||||
test = instances.testCV(numFolds, i);
|
||||
pb4.buildClassifier(training);
|
||||
@@ -138,26 +125,22 @@ public class App {
|
||||
double[] complexityStat = new double[2];
|
||||
int[] seeds = { 57, 31, 1714, 17, 23, 79, 83, 97, 7, 1 };
|
||||
String dataset;
|
||||
String debugMsg, stratMsg, normMsg;
|
||||
ArrayList<Double> timeSpent;
|
||||
ArrayList<Double> accuracy;
|
||||
ArrayList<Double> complexity;
|
||||
|
||||
debugMsg = debug ? "With debug output" : "";
|
||||
stratMsg = stratify ? "stratified" : "without stratification";
|
||||
normMsg = normalizeData ? " with normalization" : " without normalization";
|
||||
try {
|
||||
file = new File(datasetsFile);
|
||||
} catch (Exception e) {
|
||||
printAndExit(String.format("*** Error trying to read datasets file... (%s)",
|
||||
e.getMessage()));
|
||||
}
|
||||
System.out.println(String.format("%d fold cross validation %s %s %s",
|
||||
numFolds, stratMsg, debugMsg, normMsg));
|
||||
System.out.println(String.format("%d fold cross validation stratified", numFolds));
|
||||
initializeOutput();
|
||||
sc = new Scanner(file);
|
||||
while (sc.hasNextLine()) {
|
||||
dataset = sc.nextLine();
|
||||
System.out.print(String.format("Processing dataset %-30s [ ", dataset));
|
||||
if (debug && dataset.equals("balloons")) {
|
||||
printAndExit("* Check error output. Debug End.");
|
||||
}
|
||||
@@ -165,14 +148,13 @@ public class App {
|
||||
accuracy = new ArrayList<>();
|
||||
complexity = new ArrayList<>();
|
||||
for (int seed : seeds) {
|
||||
System.out.print(String.format("%d ", seed));
|
||||
// Establece la semilla
|
||||
gen = new Random(seed);
|
||||
// Obtiene los datos
|
||||
instances = getInstances(dataset);
|
||||
instances.randomize(gen);
|
||||
instances.setClassIndex(instances.numAttributes() - 1);
|
||||
System.out.println("Instances:");
|
||||
System.out.println(instances.toString());
|
||||
try {
|
||||
validation(instances, seed, accuracy, timeSpent, complexity);
|
||||
} catch (Exception e) {
|
||||
@@ -181,6 +163,7 @@ public class App {
|
||||
}
|
||||
|
||||
}
|
||||
System.out.println("]");
|
||||
accuracyStat = meanAndDeviation(accuracy);
|
||||
timeStat = meanAndDeviation(timeSpent);
|
||||
complexityStat = meanAndDeviation(complexity);
|
||||
|
Reference in New Issue
Block a user