/** Test of learn method, of class RDA. */ @Test public void testUSPS() { System.out.println("USPS"); DelimitedTextParser parser = new DelimitedTextParser(); parser.setResponseIndex(new NominalAttribute("class"), 0); try { AttributeDataset train = parser.parse("USPS Train", smile.data.parser.IOUtils.getTestDataFile("usps/zip.train")); AttributeDataset test = parser.parse("USPS Test", smile.data.parser.IOUtils.getTestDataFile("usps/zip.test")); double[][] x = train.toArray(new double[train.size()][]); int[] y = train.toArray(new int[train.size()]); double[][] testx = test.toArray(new double[test.size()][]); int[] testy = test.toArray(new int[test.size()]); RDA rda = new RDA(x, y, 0.7); int error = 0; for (int i = 0; i < testx.length; i++) { if (rda.predict(testx[i]) != testy[i]) { error++; } } System.out.format("USPS error rate = %.2f%%%n", 100.0 * error / testx.length); assertEquals(235, error); } catch (Exception ex) { System.err.println(ex); } }
/** Test of learn method, of class MEC. */ @Test public void testUSPS() { System.out.println("USPS"); DelimitedTextParser parser = new DelimitedTextParser(); parser.setResponseIndex(new NominalAttribute("class"), 0); try { AttributeDataset train = parser.parse("USPS Train", smile.data.parser.IOUtils.getTestDataFile("usps/zip.train")); AttributeDataset test = parser.parse("USPS Test", smile.data.parser.IOUtils.getTestDataFile("usps/zip.test")); double[][] x = train.toArray(new double[train.size()][]); int[] y = train.toArray(new int[train.size()]); double[][] testx = test.toArray(new double[test.size()][]); int[] testy = test.toArray(new int[test.size()]); AdjustedRandIndex ari = new AdjustedRandIndex(); RandIndex rand = new RandIndex(); MEC<double[]> mec = new MEC<double[]>(x, new EuclideanDistance(), 10, 8.0); double r = rand.measure(y, mec.getClusterLabel()); double r2 = ari.measure(y, mec.getClusterLabel()); System.out.format( "Training rand index = %.2f%%\tadjusted rand index = %.2f%%\n", 100.0 * r, 100.0 * r2); assertTrue(r > 0.85); assertTrue(r2 > 0.35); int[] p = new int[testx.length]; for (int i = 0; i < testx.length; i++) { p[i] = mec.predict(testx[i]); } r = rand.measure(testy, p); r2 = ari.measure(testy, p); System.out.format( "Testing rand index = %.2f%%\tadjusted rand index = %.2f%%\n", 100.0 * r, 100.0 * r2); assertTrue(r > 0.85); assertTrue(r2 > 0.35); } catch (Exception ex) { System.err.println(ex); } }
public CoverTreeSpeedTest() { long start = System.currentTimeMillis(); DelimitedTextParser parser = new DelimitedTextParser(); parser.setResponseIndex(new NominalAttribute("class"), 0); try { AttributeDataset train = parser.parse("USPS Train", smile.data.parser.IOUtils.getTestDataFile("usps/zip.train")); AttributeDataset test = parser.parse("USPS Test", smile.data.parser.IOUtils.getTestDataFile("usps/zip.test")); x = train.toArray(new double[train.size()][]); testx = test.toArray(new double[test.size()][]); } catch (Exception ex) { System.err.println(ex); } double time = (System.currentTimeMillis() - start) / 1000.0; System.out.format("Loading data: %.2fs\n", time); start = System.currentTimeMillis(); coverTree = new CoverTree<double[]>(x, new EuclideanDistance()); time = (System.currentTimeMillis() - start) / 1000.0; System.out.format("Building cover tree: %.2fs\n", time); }