@Test public void testSegment() { System.out.println("Segment"); MathEx.setSeed(19650217); Standardizer scaler = Standardizer.fit(Segment.x); double[][] x = scaler.transform(Segment.x); double[][] testx = scaler.transform(Segment.testx); GaussianKernel kernel = new GaussianKernel(6.4); OneVersusOne<double[]> model = OneVersusOne.fit(x, Segment.y, (xi, y) -> SVM.fit(xi, y, kernel, 100, 1E-3)); int[] prediction = Validation.test(model, testx); int error = Error.of(Segment.testy, prediction); System.out.format("Test Error = %d, Accuracy = %.2f%%%n", error, 100.0 - 100.0 * error / Segment.testx.length); assertEquals(34, 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);  }