@Test(expected = Test.None.class) public void testUSPS() throws Exception { System.out.println("USPS"); MathEx.setSeed(19650218); double[][] x = USPS.x; int[] y = USPS.y; double[][] testx = USPS.testx; int[] testy = USPS.testy; CLARANS<double[]> model = CLARANS.fit(x, MathEx::squaredDistance,10); 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.8935, r, 1E-4); assertEquals(0.4610, 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[testx.length]; for (int i = 0; i < testx.length; i++) { p[i] = model.predict(testx[i]); } 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.8807, r, 1E-4); assertEquals(0.4016, r2, 1E-4); java.nio.file.Path temp = smile.data.Serialize.write(model); smile.data.Serialize.read(temp); }
public static <T> CLARANS<T> fit(T[] data, Distance<T> distance, int k) { return fit(data, distance, k, (int) Math.round(0.0125 * k * (data.length - k))); }
CLARANS extends CentroidClustering<T, T> { public static <T> CLARANS<T> fit(T[] data, Distance<T> distance, int k) { return fit(data, distance, k, (int) Math.round(0.0125 * k * (data.length - k))); } }
CLARANS extends CentroidClustering<T, T> { public static <T> CLARANS<T> fit(T[] data, Distance<T> distance, int k) { return fit(data, distance, k, (int) Math.round(0.0125 * k * (data.length - k))); } CLARANS(double distortion, T[] medoids, int[] y, Distance<T> distance); }
CLARANS extends CentroidClustering<T, T> { public static <T> CLARANS<T> fit(T[] data, Distance<T> distance, int k) { return fit(data, distance, k, (int) Math.round(0.0125 * k * (data.length - k))); } CLARANS(double distortion, T[] medoids, int[] y, Distance<T> distance); @Override double distance(T x, T y); static CLARANS<T> fit(T[] data, Distance<T> distance, int k); static CLARANS<T> fit(T[] data, Distance<T> distance, int k, int maxNeighbor); }
CLARANS extends CentroidClustering<T, T> { public static <T> CLARANS<T> fit(T[] data, Distance<T> distance, int k) { return fit(data, distance, k, (int) Math.round(0.0125 * k * (data.length - k))); } CLARANS(double distortion, T[] medoids, int[] y, Distance<T> distance); @Override double distance(T x, T y); static CLARANS<T> fit(T[] data, Distance<T> distance, int k); static CLARANS<T> fit(T[] data, Distance<T> distance, int k, int maxNeighbor);  }