use of smile.data.parser.ArffParser in project smile by haifengl.
the class ValidationTest method testLoocv_4args_1.
/**
* Test of loocv method, of class Validation.
*/
@Test
public void testLoocv_4args_1() {
System.out.println("loocv");
ArffParser arffParser = new ArffParser();
arffParser.setResponseIndex(4);
try {
AttributeDataset weather = arffParser.parse(smile.data.parser.IOUtils.getTestDataFile("weka/weather.nominal.arff"));
double[][] x = weather.toArray(new double[weather.size()][]);
int[] y = weather.toArray(new int[weather.size()]);
DecisionTree.Trainer trainer = new DecisionTree.Trainer(3);
trainer.setAttributes(weather.attributes());
ClassificationMeasure[] measures = { new Accuracy(), new Recall(), new Precision() };
double[] results = Validation.loocv(trainer, x, y, measures);
for (int i = 0; i < measures.length; i++) {
System.out.println(measures[i] + " = " + results[i]);
}
assertEquals(0.6429, results[0], 1E-4);
} catch (Exception ex) {
System.err.println(ex);
}
}
use of smile.data.parser.ArffParser in project smile by haifengl.
the class ValidationTest method testBootstrap_5args_2.
/**
* Test of bootstrap method, of class Validation.
*/
@Test
public void testBootstrap_5args_2() {
System.out.println("bootstrap");
ArffParser parser = new ArffParser();
parser.setResponseIndex(6);
try {
AttributeDataset data = parser.parse(smile.data.parser.IOUtils.getTestDataFile("weka/cpu.arff"));
double[] y = data.toArray(new double[data.size()]);
double[][] x = data.toArray(new double[data.size()][]);
Math.standardize(x);
RBFNetwork.Trainer<double[]> trainer = new RBFNetwork.Trainer<>(new EuclideanDistance());
trainer.setNumCenters(20);
RegressionMeasure[] measures = { new RMSE(), new AbsoluteDeviation() };
double[][] results = Validation.bootstrap(100, trainer, x, y, measures);
System.out.println("100-fold bootstrap RMSE average = " + Math.mean(results[0]));
System.out.println("100-fold bootstrap RMSE std.dev = " + Math.sd(results[0]));
System.out.println("100-fold bootstrap AbsoluteDeviation average = " + Math.mean(results[1]));
System.out.println("100-fold bootstrap AbsoluteDeviation std.dev = " + Math.sd(results[1]));
} catch (Exception ex) {
System.err.println(ex);
}
}
use of smile.data.parser.ArffParser in project smile by haifengl.
the class ValidationTest method testBootstrap_5args_1.
/**
* Test of bootstrap method, of class Validation.
*/
@Test
public void testBootstrap_5args_1() {
System.out.println("bootstrap");
ArffParser arffParser = new ArffParser();
arffParser.setResponseIndex(4);
try {
AttributeDataset weather = arffParser.parse(smile.data.parser.IOUtils.getTestDataFile("weka/weather.nominal.arff"));
double[][] x = weather.toArray(new double[weather.size()][]);
int[] y = weather.toArray(new int[weather.size()]);
DecisionTree.Trainer trainer = new DecisionTree.Trainer(3);
trainer.setAttributes(weather.attributes());
ClassificationMeasure[] measures = { new Accuracy(), new Recall(), new Precision() };
double[][] results = Validation.bootstrap(100, trainer, x, y, measures);
for (int i = 0; i < 100; i++) {
for (int j = 0; j < measures.length; j++) {
System.out.format("%s = %.4f\t", measures[j], results[i][j]);
}
System.out.println();
}
System.out.println("On average:");
double[] avg = Math.colMean(results);
for (int j = 0; j < measures.length; j++) {
System.out.format("%s = %.4f\t", measures[j], avg[j]);
}
} catch (Exception ex) {
System.err.println(ex);
}
}
use of smile.data.parser.ArffParser in project smile by haifengl.
the class ValidationTest method testBootstrap_4args_2.
/**
* Test of bootstrap method, of class Validation.
*/
@Test
public void testBootstrap_4args_2() {
System.out.println("bootstrap");
ArffParser parser = new ArffParser();
parser.setResponseIndex(6);
try {
AttributeDataset data = parser.parse(smile.data.parser.IOUtils.getTestDataFile("weka/cpu.arff"));
double[] y = data.toArray(new double[data.size()]);
double[][] x = data.toArray(new double[data.size()][]);
Math.standardize(x);
RBFNetwork.Trainer<double[]> trainer = new RBFNetwork.Trainer<>(new EuclideanDistance());
trainer.setNumCenters(20);
double[] rmse = Validation.bootstrap(100, trainer, x, y);
System.out.println("100-fold bootstrap RMSE average = " + Math.mean(rmse));
System.out.println("100-fold bootstrap RMSE std.dev = " + Math.sd(rmse));
} catch (Exception ex) {
System.err.println(ex);
}
}
use of smile.data.parser.ArffParser in project useful-java-links by Vedenin.
the class SmileHelloWorld method LoadArff.
private void LoadArff() throws Exception {
ArffParser arffParser = new ArffParser();
arffParser.setResponseIndex(4);
AttributeDataset weather = arffParser.parse(this.getClass().getResourceAsStream("weather.nominal.arff"));
println("name" + weather.getName());
println("responce " + weather.response());
println("attributes = " + Arrays.toString(weather.attributes()));
println("Data: ");
println(" x : y : weight");
weather.forEach((x) -> println(Arrays.toString(x.x) + " : " + x.y + " : " + x.weight));
}
Aggregations