use of smile.data.parser.ArffParser in project smile by haifengl.
the class ValidationTest method testCv_5args_1.
/**
* Test of cv method, of class Validation.
*/
@Test
public void testCv_5args_1() {
System.out.println("cv");
ArffParser arffParser = new ArffParser();
arffParser.setResponseIndex(4);
try {
AttributeDataset iris = arffParser.parse(smile.data.parser.IOUtils.getTestDataFile("weka/iris.arff"));
double[][] x = iris.toArray(new double[iris.size()][]);
int[] y = iris.toArray(new int[iris.size()]);
ClassifierTrainer<double[]> trainer = new LDA.Trainer();
ClassificationMeasure[] measures = { new Accuracy() };
double[] results = Validation.cv(10, trainer, x, y, measures);
for (int i = 0; i < measures.length; i++) {
System.out.println(measures[i] + " = " + results[i]);
}
} catch (Exception ex) {
System.err.println(ex);
}
}
use of smile.data.parser.ArffParser in project smile by haifengl.
the class ValidationTest method testCv_4args_1.
/**
* Test of cv method, of class Validation.
*/
@Test
public void testCv_4args_1() {
System.out.println("cv");
ArffParser arffParser = new ArffParser();
arffParser.setResponseIndex(4);
try {
AttributeDataset iris = arffParser.parse(smile.data.parser.IOUtils.getTestDataFile("weka/iris.arff"));
double[][] x = iris.toArray(new double[iris.size()][]);
int[] y = iris.toArray(new int[iris.size()]);
ClassifierTrainer<double[]> trainer = new LDA.Trainer();
double accuracy = Validation.cv(10, trainer, x, y);
System.out.println("10-fold CV accuracy = " + accuracy);
} catch (Exception ex) {
System.err.println(ex);
}
}
use of smile.data.parser.ArffParser in project smile by haifengl.
the class ValidationTest method testTest_4args_2.
/**
* Test of test method, of class Validation.
*/
@Test
public void testTest_4args_2() {
System.out.println("test");
ArffParser parser = new ArffParser();
parser.setResponseIndex(6);
try {
AttributeDataset data = parser.parse(smile.data.parser.IOUtils.getTestDataFile("weka/cpu.arff"));
double[] datay = data.toArray(new double[data.size()]);
double[][] datax = data.toArray(new double[data.size()][]);
Math.standardize(datax);
int n = datax.length;
int m = 3 * n / 4;
double[][] x = new double[m][];
double[] y = new double[m];
double[][] testx = new double[n - m][];
double[] testy = new double[n - m];
int[] index = Math.permutate(n);
for (int i = 0; i < m; i++) {
x[i] = datax[index[i]];
y[i] = datay[index[i]];
}
for (int i = m; i < n; i++) {
testx[i - m] = datax[index[i]];
testy[i - m] = datay[index[i]];
}
double[][] centers = new double[20][];
RadialBasisFunction[] rbf = SmileUtils.learnGaussianRadialBasis(x, centers, 2);
RBFNetwork<double[]> rkhs = new RBFNetwork<>(x, y, new EuclideanDistance(), rbf, centers);
RegressionMeasure[] measures = { new RMSE(), new AbsoluteDeviation() };
double[] results = Validation.test(rkhs, testx, testy, measures);
System.out.println("RMSE = " + results[0]);
System.out.println("Absolute Deviation = " + results[1]);
} catch (Exception ex) {
System.err.println(ex);
}
}
use of smile.data.parser.ArffParser in project smile by haifengl.
the class ValidationTest method testLoocv_4args_2.
/**
* Test of loocv method, of class Validation.
*/
@Test
public void testLoocv_4args_2() {
System.out.println("loocv");
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.loocv(trainer, x, y, measures);
System.out.println("RMSE = " + results[0]);
System.out.println("Absolute Deviation = " + 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_4args_1.
/**
* Test of bootstrap method, of class Validation.
*/
@Test
public void testBootstrap_4args_1() {
System.out.println("bootstrap");
ArffParser arffParser = new ArffParser();
arffParser.setResponseIndex(4);
try {
AttributeDataset iris = arffParser.parse(smile.data.parser.IOUtils.getTestDataFile("weka/iris.arff"));
double[][] x = iris.toArray(new double[iris.size()][]);
int[] y = iris.toArray(new int[iris.size()]);
ClassifierTrainer<double[]> trainer = new LDA.Trainer();
double[] accuracy = Validation.bootstrap(100, trainer, x, y);
System.out.println("100-fold bootstrap accuracy average = " + Math.mean(accuracy));
System.out.println("100-fold bootstrap accuracy std.dev = " + Math.sd(accuracy));
} catch (Exception ex) {
System.err.println(ex);
}
}
Aggregations