Search in sources :

Example 1 with LibsvmParser

use of smile.data.parser.LibsvmParser in project smile by haifengl.

the class SIBTest method testParseNG20.

/**
     * Test of parse method, of class SIB.
     */
@Test
public void testParseNG20() throws Exception {
    System.out.println("NG20");
    LibsvmParser parser = new LibsvmParser();
    try {
        SparseDataset train = parser.parse("NG20 Train", smile.data.parser.IOUtils.getTestDataFile("libsvm/news20.dat"));
        SparseDataset test = parser.parse("NG20 Test", smile.data.parser.IOUtils.getTestDataFile("libsvm/news20.t.dat"));
        int[] y = train.toArray(new int[train.size()]);
        int[] testy = test.toArray(new int[test.size()]);
        SIB sib = new SIB(train, 20, 100, 8);
        System.out.println(sib);
        AdjustedRandIndex ari = new AdjustedRandIndex();
        RandIndex rand = new RandIndex();
        double r = rand.measure(y, sib.getClusterLabel());
        double r2 = ari.measure(y, sib.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.2);
        int[] p = new int[test.size()];
        for (int i = 0; i < test.size(); i++) {
            p[i] = sib.predict(test.get(i).x);
        }
        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.2);
    } catch (Exception ex) {
        System.err.println(ex);
    }
}
Also used : LibsvmParser(smile.data.parser.LibsvmParser) SparseDataset(smile.data.SparseDataset) AdjustedRandIndex(smile.validation.AdjustedRandIndex) RandIndex(smile.validation.RandIndex) AdjustedRandIndex(smile.validation.AdjustedRandIndex) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 SparseDataset (smile.data.SparseDataset)1 LibsvmParser (smile.data.parser.LibsvmParser)1 AdjustedRandIndex (smile.validation.AdjustedRandIndex)1 RandIndex (smile.validation.RandIndex)1