@Test(expected = Test.None.class) public void testSVMGuide1() throws IOException { System.out.println("svmguide1"); MathEx.setSeed(19650218); Dataset<Instance<SparseArray>> train = Read.libsvm(smile.util.Paths.getTestData("libsvm/svmguide1")); Dataset<Instance<SparseArray>> test = Read.libsvm(smile.util.Paths.getTestData("libsvm/svmguide1.t")); int n = train.size(); double[][] x = new double[n][4]; int[] y = new int[n]; for (int i = 0; i < n; i++) { Instance<SparseArray> sample = train.get(i); for (SparseArray.Entry e : sample.x()) { x[i][e.i] = e.x; } y[i] = sample.label() > 0 ? +1 : -1; } n = test.size(); double[][] testx = new double[n][4]; int[] testy = new int[n]; for (int i = 0; i < n; i++) { Instance<SparseArray> sample = test.get(i); for (SparseArray.Entry e : sample.x()) { testx[i][e.i] = e.x; } testy[i] = sample.label() > 0 ? +1 : -1; } GaussianKernel kernel = new GaussianKernel(90); SVM<double[]> model = SVM.fit(x, y, kernel, 100, 1E-3); int[] prediction = Validation.test(model, testx); int error = Error.of(testy, prediction); System.out.format("Test Error = %d, Accuracy = %.2f%%%n", error, 100.0 - 100.0 * error / testx.length); assertEquals(130, error); }
public static Classifier<double[]> fit(double[][] x, int[] y, double C, double tol) { LASVM<double[]> lasvm = new LASVM<>(new LinearKernel(), C, tol); KernelMachine<double[]> svm = lasvm.fit(x, y); return new Classifier<double[]>() { LinearKernelMachine model = LinearKernelMachine.of(svm); @Override public int predict(double[] x) { return model.f(x) > 0 ? +1 : -1; } }; }
SVM extends KernelMachine<T> implements Classifier<T> { public static Classifier<double[]> fit(double[][] x, int[] y, double C, double tol) { LASVM<double[]> lasvm = new LASVM<>(new LinearKernel(), C, tol); KernelMachine<double[]> svm = lasvm.fit(x, y); return new Classifier<double[]>() { LinearKernelMachine model = LinearKernelMachine.of(svm); @Override public int predict(double[] x) { return model.f(x) > 0 ? +1 : -1; } }; } }
SVM extends KernelMachine<T> implements Classifier<T> { public static Classifier<double[]> fit(double[][] x, int[] y, double C, double tol) { LASVM<double[]> lasvm = new LASVM<>(new LinearKernel(), C, tol); KernelMachine<double[]> svm = lasvm.fit(x, y); return new Classifier<double[]>() { LinearKernelMachine model = LinearKernelMachine.of(svm); @Override public int predict(double[] x) { return model.f(x) > 0 ? +1 : -1; } }; } SVM(MercerKernel<T> kernel, T[] instances, double[] weight, double b); }
SVM extends KernelMachine<T> implements Classifier<T> { public static Classifier<double[]> fit(double[][] x, int[] y, double C, double tol) { LASVM<double[]> lasvm = new LASVM<>(new LinearKernel(), C, tol); KernelMachine<double[]> svm = lasvm.fit(x, y); return new Classifier<double[]>() { LinearKernelMachine model = LinearKernelMachine.of(svm); @Override public int predict(double[] x) { return model.f(x) > 0 ? +1 : -1; } }; } SVM(MercerKernel<T> kernel, T[] instances, double[] weight, double b); @Override int predict(T x); static Classifier<double[]> fit(double[][] x, int[] y, double C, double tol); static Classifier<int[]> fit(int[][] x, int[] y, int p, double C, double tol); static Classifier<SparseArray> fit(SparseArray[] x, int[] y, int p, double C, double tol); static SVM<T> fit(T[] x, int[] y, MercerKernel<T> kernel, double C, double tol); }
SVM extends KernelMachine<T> implements Classifier<T> { public static Classifier<double[]> fit(double[][] x, int[] y, double C, double tol) { LASVM<double[]> lasvm = new LASVM<>(new LinearKernel(), C, tol); KernelMachine<double[]> svm = lasvm.fit(x, y); return new Classifier<double[]>() { LinearKernelMachine model = LinearKernelMachine.of(svm); @Override public int predict(double[] x) { return model.f(x) > 0 ? +1 : -1; } }; } SVM(MercerKernel<T> kernel, T[] instances, double[] weight, double b); @Override int predict(T x); static Classifier<double[]> fit(double[][] x, int[] y, double C, double tol); static Classifier<int[]> fit(int[][] x, int[] y, int p, double C, double tol); static Classifier<SparseArray> fit(SparseArray[] x, int[] y, int p, double C, double tol); static SVM<T> fit(T[] x, int[] y, MercerKernel<T> kernel, double C, double tol);  }