Пример #1
0
  private Classification writeRead(Classification src, File file) throws IOException {
    Collection<MLArray> mlArrays = new ArrayList<>();
    src.toMLData("", mlArrays);
    new MatFileWriter().write(file, mlArrays);

    Map<String, MLArray> content = new MatFileReader(file).getContent();
    Classification res = new Classification();
    res.fromMLData("", content);
    return res;
  }
Пример #2
0
  @Test
  public void testOneVsAll() throws IOException {
    TrainingSet trainingSet =
        new TrainingSet()
            .setModelCalculator(new LogisticModel())
            .setX(X)
            .setXTransformation(new XTransformation(true, null, null))
            .setRegularization(0.1)
            .setMatrixFactory(factory);

    Classification classifier = new Classification();
    classifier.trainOneVsAll(trainingSet, y, Executors.newFixedThreadPool(5));
    ClassificationAccuracy accuracy = classifier.getAccuracy(X, y);
    System.out.println("Training set accuracy: " + accuracy.getCrossLabelAccuracy() * 100);

    Classification cls1 = writeRead(classifier, new File("./target/ex3classification.mat"));
    assertArrayEquals(classifier.getLabels(X), cls1.getLabels(X));
  }