@Test(expected = Test.None.class) public void testParseNG20() throws Exception { System.out.println("NG20"); MathEx.setSeed(19650218); Dataset<Instance<SparseArray>> train = Read.libsvm(smile.util.Paths.getTestData("libsvm/news20.dat")); Dataset<Instance<SparseArray>> test = Read.libsvm(smile.util.Paths.getTestData("libsvm/news20.t.dat")); SparseArray[] trainx = train.stream().map(Instance<SparseArray>::x).toArray(SparseArray[]::new); int[] y = train.stream().mapToInt(i -> i.label()).toArray(); int[] testy = test.stream().mapToInt(i -> i.label()).toArray(); SIB model = SIB.fit(trainx, 20); System.out.println(model); double r = RandIndex.of(y, model.y); double r2 = AdjustedRandIndex.of(y, model.y); System.out.format("Training rand index = %.2f%%, adjusted rand index = %.2f%%%n", 100.0 * r, 100.0 * r2); assertEquals(0.8842, r, 1E-4); assertEquals(0.2327, r2, 1E-4); System.out.format("MI = %.2f%n", MutualInformation.of(y, model.y)); System.out.format("NMI.joint = %.2f%%%n", 100 * NormalizedMutualInformation.joint(y, model.y)); System.out.format("NMI.max = %.2f%%%n", 100 * NormalizedMutualInformation.max(y, model.y)); System.out.format("NMI.min = %.2f%%%n", 100 * NormalizedMutualInformation.min(y, model.y)); System.out.format("NMI.sum = %.2f%%%n", 100 * NormalizedMutualInformation.sum(y, model.y)); System.out.format("NMI.sqrt = %.2f%%%n", 100 * NormalizedMutualInformation.sqrt(y, model.y)); int[] p = new int[test.size()]; for (int i = 0; i < test.size(); i++) { p[i] = model.predict(test.get(i).x()); } r = RandIndex.of(testy, p); r2 = AdjustedRandIndex.of(testy, p); System.out.format("Testing rand index = %.2f%%, adjusted rand index = %.2f%%%n", 100.0 * r, 100.0 * r2); assertEquals(0.8782, r, 1E-4); assertEquals(0.2287, r2, 1E-4); java.nio.file.Path temp = smile.data.Serialize.write(model); smile.data.Serialize.read(temp); }
public static SIB fit(SparseArray[] data, int k) { return fit(data, k, 100); }
SIB extends CentroidClustering<double[], SparseArray> { public static SIB fit(SparseArray[] data, int k) { return fit(data, k, 100); } }
SIB extends CentroidClustering<double[], SparseArray> { public static SIB fit(SparseArray[] data, int k) { return fit(data, k, 100); } SIB(double distortion, double[][] centroids, int[] y); }
SIB extends CentroidClustering<double[], SparseArray> { public static SIB fit(SparseArray[] data, int k) { return fit(data, k, 100); } SIB(double distortion, double[][] centroids, int[] y); @Override double distance(double[] x, SparseArray y); static SIB fit(SparseArray[] data, int k); static SIB fit(SparseArray[] data, int k, int maxIter); }
SIB extends CentroidClustering<double[], SparseArray> { public static SIB fit(SparseArray[] data, int k) { return fit(data, k, 100); } SIB(double distortion, double[][] centroids, int[] y); @Override double distance(double[] x, SparseArray y); static SIB fit(SparseArray[] data, int k); static SIB fit(SparseArray[] data, int k, int maxIter);  }