@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.winesOrdinal(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    DummyXMinMaxNormalizer df = MLBuilder.create(new DummyXMinMaxNormalizer.TrainingParameters(), configuration);
    df.fit_transform(trainingData);
    df.save(storageName);
    String datasetName = "winesOrdinal";
    trainingData.save(datasetName);
    trainingData.close();
    OrdinalRegression.TrainingParameters param = new OrdinalRegression.TrainingParameters();
    param.setTotalIterations(100);
    param.setL2(0.001);
    OrdinalRegression instance = MLBuilder.create(param, configuration);
    trainingData = Dataframe.Builder.load(datasetName, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    df.denormalize(trainingData);
    trainingData.delete();
    instance.close();
    df.close();
    df = MLBuilder.load(DummyXMinMaxNormalizer.class, storageName, configuration);
    instance = MLBuilder.load(OrdinalRegression.class, storageName, configuration);
    df.transform(validationData);
    instance.predict(validationData);
    df.denormalize(validationData);
    Map<Integer, Object> expResult = new HashMap<>();
    Map<Integer, Object> result = new HashMap<>();
    for (Map.Entry<Integer, Record> e : validationData.entries()) {
        Integer rId = e.getKey();
        Record r = e.getValue();
        expResult.put(rId, r.getY());
        result.put(rId, r.getYPredicted());
    }
    assertEquals(expResult, result);
    df.delete();
    instance.delete();
    validationData.close();
}

@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.winesOrdinal(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    numericalScaler.save(storageName);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    categoricalEncoder.save(storageName);
    String datasetName = "winesOrdinal";
    trainingData.save(datasetName);
    trainingData.close();
    OrdinalRegression.TrainingParameters param = new OrdinalRegression.TrainingParameters();
    param.setTotalIterations(100);
    param.setL2(0.001);
    OrdinalRegression instance = MLBuilder.create(param, configuration);
    trainingData = Dataframe.Builder.load(datasetName, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    trainingData.delete();
    instance.close();
    numericalScaler.close();
    categoricalEncoder.close();
    numericalScaler = MLBuilder.load(MinMaxScaler.class, storageName, configuration);
    categoricalEncoder = MLBuilder.load(CornerConstraintsEncoder.class, storageName, configuration);
    instance = MLBuilder.load(OrdinalRegression.class, storageName, configuration);
    numericalScaler.transform(validationData);
    categoricalEncoder.transform(validationData);
    instance.predict(validationData);
    Map<Integer, Object> expResult = new HashMap<>();
    Map<Integer, Object> result = new HashMap<>();
    for (Map.Entry<Integer, Record> e : validationData.entries()) {
        Integer rId = e.getKey();
        Record r = e.getValue();
        expResult.put(rId, r.getY());
        result.put(rId, r.getYPredicted());
    }
    assertEquals(expResult, result);
    numericalScaler.delete();
    categoricalEncoder.delete();
    instance.delete();
    validationData.close();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("testKFoldCrossValidation");
    Configuration configuration = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.winesOrdinal(configuration);
    Dataframe trainingData = data[0];
    data[1].close();
    DummyXMinMaxNormalizer df = MLBuilder.create(new DummyXMinMaxNormalizer.TrainingParameters(), configuration);
    df.fit_transform(trainingData);
    OrdinalRegression.TrainingParameters param = new OrdinalRegression.TrainingParameters();
    param.setTotalIterations(100);
    param.setL2(0.001);
    ClassificationMetrics vm = new Validator<>(ClassificationMetrics.class, configuration).validate(new KFoldSplitter(k).split(trainingData), param);
    df.denormalize(trainingData);
    double expResult = 0.9823403146614675;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.close();
    trainingData.close();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("testKFoldCrossValidation");
    Configuration configuration = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.winesOrdinal(configuration);
    Dataframe trainingData = data[0];
    data[1].close();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    OrdinalRegression.TrainingParameters param = new OrdinalRegression.TrainingParameters();
    param.setTotalIterations(100);
    param.setL2(0.001);
    ClassificationMetrics vm = new Validator<>(ClassificationMetrics.class, configuration).validate(new KFoldSplitter(k).split(trainingData), param);
    double expResult = 0.9823403146614675;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    numericalScaler.close();
    categoricalEncoder.close();
    trainingData.close();
}


@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.carsCategorical(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = MLBuilder.create(new DummyXYMinMaxNormalizer.TrainingParameters(), configuration);
    df.fit_transform(trainingData);
    df.save(storageName);
    SoftMaxRegression.TrainingParameters param = new SoftMaxRegression.TrainingParameters();
    param.setTotalIterations(2000);
    param.setL2(0.001);
    SoftMaxRegression instance = MLBuilder.create(param, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    df.denormalize(trainingData);
    trainingData.close();
    instance.close();
    df.close();
    df = MLBuilder.load(DummyXYMinMaxNormalizer.class, storageName, configuration);
    instance = MLBuilder.load(SoftMaxRegression.class, storageName, configuration);
    df.transform(validationData);
    instance.predict(validationData);
    df.denormalize(validationData);
    Map<Integer, Object> expResult = new HashMap<>();
    Map<Integer, Object> result = new HashMap<>();
    for (Map.Entry<Integer, Record> e : validationData.entries()) {
        Integer rId = e.getKey();
        Record r = e.getValue();
        expResult.put(rId, r.getY());
        result.put(rId, r.getYPredicted());
    }
    assertEquals(expResult, result);
    df.delete();
    instance.delete();
    validationData.close();
}

@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.carsCategorical(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    nsParams.setScaleResponse(true);
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    numericalScaler.save(storageName);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    categoricalEncoder.save(storageName);
    SoftMaxRegression.TrainingParameters param = new SoftMaxRegression.TrainingParameters();
    param.setTotalIterations(2000);
    param.setL2(0.001);
    SoftMaxRegression instance = MLBuilder.create(param, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    trainingData.close();
    instance.close();
    numericalScaler.close();
    categoricalEncoder.close();
    numericalScaler = MLBuilder.load(MinMaxScaler.class, storageName, configuration);
    categoricalEncoder = MLBuilder.load(CornerConstraintsEncoder.class, storageName, configuration);
    instance = MLBuilder.load(SoftMaxRegression.class, storageName, configuration);
    numericalScaler.transform(validationData);
    categoricalEncoder.transform(validationData);
    instance.predict(validationData);
    Map<Integer, Object> expResult = new HashMap<>();
    Map<Integer, Object> result = new HashMap<>();
    for (Map.Entry<Integer, Record> e : validationData.entries()) {
        Integer rId = e.getKey();
        Record r = e.getValue();
        expResult.put(rId, r.getY());
        result.put(rId, r.getYPredicted());
    }
    assertEquals(expResult, result);
    numericalScaler.delete();
    categoricalEncoder.delete();
    instance.delete();
    validationData.close();
}

public void fit_transform(Dataframe trainingData) {
    fit(trainingData);
    transform(trainingData);
}

@Test
public void testKFoldCrossValidation() {
    logger.info("testKFoldCrossValidation");
    Configuration configuration = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(configuration);
    Dataframe trainingData = data[0];
    data[1].close();
    XMinMaxNormalizer df = MLBuilder.create(new XMinMaxNormalizer.TrainingParameters(), configuration);
    df.fit_transform(trainingData);
    SoftMaxRegression.TrainingParameters param = new SoftMaxRegression.TrainingParameters();
    param.setTotalIterations(30);
    param.setL1(0.0001);
    param.setL2(0.0001);
    ClassificationMetrics vm = new Validator<>(ClassificationMetrics.class, configuration).validate(new KFoldSplitter(k).split(trainingData), param);
    df.denormalize(trainingData);
    double expResult = 0.7557492507492508;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.close();
    trainingData.close();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("testKFoldCrossValidation");
    Configuration configuration = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(configuration);
    Dataframe trainingData = data[0];
    data[1].close();
    MinMaxScaler scaler = MLBuilder.create(new MinMaxScaler.TrainingParameters(), configuration);
    scaler.fit_transform(trainingData);
    SoftMaxRegression.TrainingParameters param = new SoftMaxRegression.TrainingParameters();
    param.setTotalIterations(30);
    param.setL1(0.0001);
    param.setL2(0.0001);
    ClassificationMetrics vm = new Validator<>(ClassificationMetrics.class, configuration).validate(new KFoldSplitter(k).split(trainingData), param);
    double expResult = 0.7557492507492508;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    scaler.close();
    trainingData.close();
}


@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.carsCategorical(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = MLBuilder.create(new DummyXYMinMaxNormalizer.TrainingParameters(), configuration);
    df.fit_transform(trainingData);
    df.save(storageName);
    SupportVectorMachine.TrainingParameters param = new SupportVectorMachine.TrainingParameters();
    param.getSvmParameter().kernel_type = svm_parameter.RBF;
    SupportVectorMachine instance = MLBuilder.create(param, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    df.denormalize(trainingData);
    trainingData.close();
    instance.close();
    df.close();
    df = MLBuilder.load(DummyXYMinMaxNormalizer.class, storageName, configuration);
    instance = MLBuilder.load(SupportVectorMachine.class, storageName, configuration);
    df.transform(validationData);
    instance.predict(validationData);
    df.denormalize(validationData);
    Map<Integer, Object> expResult = new HashMap<>();
    Map<Integer, Object> result = new HashMap<>();
    for (Map.Entry<Integer, Record> e : validationData.entries()) {
        Integer rId = e.getKey();
        Record r = e.getValue();
        expResult.put(rId, r.getY());
        result.put(rId, r.getYPredicted());
    }
    assertEquals(expResult, result);
    df.delete();
    instance.delete();
    validationData.close();
}

@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.carsCategorical(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    nsParams.setScaleResponse(true);
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    numericalScaler.save(storageName);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    categoricalEncoder.save(storageName);
    SupportVectorMachine.TrainingParameters param = new SupportVectorMachine.TrainingParameters();
    param.getSvmParameter().kernel_type = svm_parameter.RBF;
    SupportVectorMachine instance = MLBuilder.create(param, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    trainingData.close();
    instance.close();
    numericalScaler.close();
    categoricalEncoder.close();
    numericalScaler = MLBuilder.load(MinMaxScaler.class, storageName, configuration);
    categoricalEncoder = MLBuilder.load(CornerConstraintsEncoder.class, storageName, configuration);
    instance = MLBuilder.load(SupportVectorMachine.class, storageName, configuration);
    numericalScaler.transform(validationData);
    categoricalEncoder.transform(validationData);
    instance.predict(validationData);
    Map<Integer, Object> expResult = new HashMap<>();
    Map<Integer, Object> result = new HashMap<>();
    for (Map.Entry<Integer, Record> e : validationData.entries()) {
        Integer rId = e.getKey();
        Record r = e.getValue();
        expResult.put(rId, r.getY());
        result.put(rId, r.getYPredicted());
    }
    assertEquals(expResult, result);
    numericalScaler.delete();
    categoricalEncoder.delete();
    instance.delete();
    validationData.close();
}


@Test
public void testKFoldCrossValidation() {
    logger.info("testKFoldCrossValidation");
    Configuration configuration = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.heartDiseaseClusters(configuration);
    Dataframe trainingData = data[0];
    data[1].close();
    DummyXYMinMaxNormalizer df = MLBuilder.create(new DummyXYMinMaxNormalizer.TrainingParameters(), configuration);
    df.fit_transform(trainingData);
    HierarchicalAgglomerative.TrainingParameters param = new HierarchicalAgglomerative.TrainingParameters();
    param.setDistanceMethod(HierarchicalAgglomerative.TrainingParameters.Distance.EUCLIDIAN);
    param.setLinkageMethod(HierarchicalAgglomerative.TrainingParameters.Linkage.COMPLETE);
    param.setMinClustersThreshold(2);
    param.setMaxDistanceThreshold(Double.MAX_VALUE);
    ClusteringMetrics vm = new Validator<>(ClusteringMetrics.class, configuration).validate(new KFoldSplitter(k).split(trainingData), param);
    df.denormalize(trainingData);
    double expResult = 0.7666666666666667;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.close();
    trainingData.close();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("testKFoldCrossValidation");
    Configuration configuration = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.heartDiseaseClusters(configuration);
    Dataframe trainingData = data[0];
    data[1].close();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    nsParams.setScaleResponse(true);
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    HierarchicalAgglomerative.TrainingParameters param = new HierarchicalAgglomerative.TrainingParameters();
    param.setDistanceMethod(HierarchicalAgglomerative.TrainingParameters.Distance.EUCLIDIAN);
    param.setLinkageMethod(HierarchicalAgglomerative.TrainingParameters.Linkage.COMPLETE);
    param.setMinClustersThreshold(2);
    param.setMaxDistanceThreshold(Double.MAX_VALUE);
    ClusteringMetrics vm = new Validator<>(ClusteringMetrics.class, configuration).validate(new KFoldSplitter(k).split(trainingData), param);
    double expResult = 0.7666666666666667;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    numericalScaler.close();
    categoricalEncoder.close();
    trainingData.close();
}

@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.heartDiseaseClusters(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = MLBuilder.create(new DummyXYMinMaxNormalizer.TrainingParameters(), configuration);
    df.fit_transform(trainingData);
    df.save(storageName);
    HierarchicalAgglomerative.TrainingParameters param = new HierarchicalAgglomerative.TrainingParameters();
    param.setDistanceMethod(HierarchicalAgglomerative.TrainingParameters.Distance.EUCLIDIAN);
    param.setLinkageMethod(HierarchicalAgglomerative.TrainingParameters.Linkage.COMPLETE);
    param.setMinClustersThreshold(2);
    param.setMaxDistanceThreshold(Double.MAX_VALUE);
    HierarchicalAgglomerative instance = MLBuilder.create(param, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    df.denormalize(trainingData);
    trainingData.close();
    instance.close();
    df.close();
    df = MLBuilder.load(DummyXYMinMaxNormalizer.class, storageName, configuration);
    instance = MLBuilder.load(HierarchicalAgglomerative.class, storageName, configuration);
    df.transform(validationData);
    instance.predict(validationData);
    ClusteringMetrics vm = new ClusteringMetrics(validationData);
    df.denormalize(validationData);
    double expResult = 1.0;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    validationData.close();
}

@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.heartDiseaseClusters(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    nsParams.setScaleResponse(true);
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    numericalScaler.save(storageName);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    categoricalEncoder.save(storageName);
    HierarchicalAgglomerative.TrainingParameters param = new HierarchicalAgglomerative.TrainingParameters();
    param.setDistanceMethod(HierarchicalAgglomerative.TrainingParameters.Distance.EUCLIDIAN);
    param.setLinkageMethod(HierarchicalAgglomerative.TrainingParameters.Linkage.COMPLETE);
    param.setMinClustersThreshold(2);
    param.setMaxDistanceThreshold(Double.MAX_VALUE);
    HierarchicalAgglomerative instance = MLBuilder.create(param, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    trainingData.close();
    instance.close();
    numericalScaler.close();
    categoricalEncoder.close();
    numericalScaler = MLBuilder.load(MinMaxScaler.class, storageName, configuration);
    categoricalEncoder = MLBuilder.load(CornerConstraintsEncoder.class, storageName, configuration);
    instance = MLBuilder.load(HierarchicalAgglomerative.class, storageName, configuration);
    numericalScaler.transform(validationData);
    categoricalEncoder.transform(validationData);
    instance.predict(validationData);
    ClusteringMetrics vm = new ClusteringMetrics(validationData);
    double expResult = 1.0;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    numericalScaler.delete();
    categoricalEncoder.delete();
    instance.delete();
    validationData.close();
}


@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.heartDiseaseClusters(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = MLBuilder.create(new DummyXYMinMaxNormalizer.TrainingParameters(), configuration);
    df.fit_transform(trainingData);
    df.save(storageName);
    Kmeans.TrainingParameters param = new Kmeans.TrainingParameters();
    param.setK(2);
    param.setMaxIterations(200);
    param.setInitializationMethod(Kmeans.TrainingParameters.Initialization.FORGY);
    param.setDistanceMethod(Kmeans.TrainingParameters.Distance.EUCLIDIAN);
    param.setWeighted(false);
    param.setCategoricalGamaMultiplier(1.0);
    param.setSubsetFurthestFirstcValue(2.0);
    Kmeans instance = MLBuilder.create(param, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    df.denormalize(trainingData);
    trainingData.close();
    instance.close();
    df.close();
    df = MLBuilder.load(DummyXYMinMaxNormalizer.class, storageName, configuration);
    instance = MLBuilder.load(Kmeans.class, storageName, configuration);
    df.transform(validationData);
    instance.predict(validationData);
    ClusteringMetrics vm = new ClusteringMetrics(validationData);
    df.denormalize(validationData);
    double expResult = 1.0;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    validationData.close();
}

@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.heartDiseaseClusters(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    nsParams.setScaleResponse(true);
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    numericalScaler.save(storageName);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    categoricalEncoder.save(storageName);
    Kmeans.TrainingParameters param = new Kmeans.TrainingParameters();
    param.setK(2);
    param.setMaxIterations(200);
    param.setInitializationMethod(Kmeans.TrainingParameters.Initialization.FORGY);
    param.setDistanceMethod(Kmeans.TrainingParameters.Distance.EUCLIDIAN);
    param.setWeighted(false);
    param.setCategoricalGamaMultiplier(1.0);
    param.setSubsetFurthestFirstcValue(2.0);
    Kmeans instance = MLBuilder.create(param, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    trainingData.close();
    instance.close();
    numericalScaler.close();
    categoricalEncoder.close();
    numericalScaler = MLBuilder.load(MinMaxScaler.class, storageName, configuration);
    categoricalEncoder = MLBuilder.load(CornerConstraintsEncoder.class, storageName, configuration);
    instance = MLBuilder.load(Kmeans.class, storageName, configuration);
    numericalScaler.transform(validationData);
    categoricalEncoder.transform(validationData);
    instance.predict(validationData);
    ClusteringMetrics vm = new ClusteringMetrics(validationData);
    double expResult = 1.0;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    numericalScaler.delete();
    categoricalEncoder.delete();
    instance.delete();
    validationData.close();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("testKFoldCrossValidation");
    Configuration configuration = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.heartDiseaseClusters(configuration);
    Dataframe trainingData = data[0];
    data[1].close();
    DummyXYMinMaxNormalizer df = MLBuilder.create(new DummyXYMinMaxNormalizer.TrainingParameters(), configuration);
    df.fit_transform(trainingData);
    Kmeans.TrainingParameters param = new Kmeans.TrainingParameters();
    param.setK(2);
    param.setMaxIterations(200);
    param.setInitializationMethod(Kmeans.TrainingParameters.Initialization.FORGY);
    param.setDistanceMethod(Kmeans.TrainingParameters.Distance.EUCLIDIAN);
    param.setWeighted(false);
    param.setCategoricalGamaMultiplier(1.0);
    param.setSubsetFurthestFirstcValue(2.0);
    ClusteringMetrics vm = new Validator<>(ClusteringMetrics.class, configuration).validate(new KFoldSplitter(k).split(trainingData), param);
    df.denormalize(trainingData);
    double expResult = 0.7888888888888889;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.close();
    trainingData.close();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("testKFoldCrossValidation");
    Configuration configuration = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.heartDiseaseClusters(configuration);
    Dataframe trainingData = data[0];
    data[1].close();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    nsParams.setScaleResponse(true);
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    Kmeans.TrainingParameters param = new Kmeans.TrainingParameters();
    param.setK(2);
    param.setMaxIterations(200);
    param.setInitializationMethod(Kmeans.TrainingParameters.Initialization.FORGY);
    param.setDistanceMethod(Kmeans.TrainingParameters.Distance.EUCLIDIAN);
    param.setWeighted(false);
    param.setCategoricalGamaMultiplier(1.0);
    param.setSubsetFurthestFirstcValue(2.0);
    ClusteringMetrics vm = new Validator<>(ClusteringMetrics.class, configuration).validate(new KFoldSplitter(k).split(trainingData), param);
    double expResult = 0.7888888888888889;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    numericalScaler.close();
    categoricalEncoder.close();
    trainingData.close();
}


@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.carsCategorical(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = MLBuilder.create(new DummyXYMinMaxNormalizer.TrainingParameters(), configuration);
    df.fit_transform(trainingData);
    df.save(storageName);
    Adaboost.TrainingParameters param = new Adaboost.TrainingParameters();
    param.setMaxWeakClassifiers(5);
    MultinomialNaiveBayes.TrainingParameters trainingParameters = new MultinomialNaiveBayes.TrainingParameters();
    trainingParameters.setMultiProbabilityWeighted(true);
    param.setWeakClassifierTrainingParameters(trainingParameters);
    Adaboost instance = MLBuilder.create(param, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    df.denormalize(trainingData);
    trainingData.close();
    instance.close();
    df.close();
    df = MLBuilder.load(DummyXYMinMaxNormalizer.class, storageName, configuration);
    instance = MLBuilder.load(Adaboost.class, storageName, configuration);
    df.transform(validationData);
    instance.predict(validationData);
    df.denormalize(validationData);
    Map<Integer, Object> expResult = new HashMap<>();
    Map<Integer, Object> result = new HashMap<>();
    for (Map.Entry<Integer, Record> e : validationData.entries()) {
        Integer rId = e.getKey();
        Record r = e.getValue();
        expResult.put(rId, r.getY());
        result.put(rId, r.getYPredicted());
    }
    assertEquals(expResult, result);
    df.delete();
    instance.delete();
    validationData.close();
}

@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.carsCategorical(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    nsParams.setScaleResponse(true);
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    numericalScaler.save(storageName);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    categoricalEncoder.save(storageName);
    Adaboost.TrainingParameters param = new Adaboost.TrainingParameters();
    param.setMaxWeakClassifiers(5);
    MultinomialNaiveBayes.TrainingParameters trainingParameters = new MultinomialNaiveBayes.TrainingParameters();
    trainingParameters.setMultiProbabilityWeighted(true);
    param.setWeakClassifierTrainingParameters(trainingParameters);
    Adaboost instance = MLBuilder.create(param, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    instance.close();
    numericalScaler.close();
    categoricalEncoder.close();
    numericalScaler = MLBuilder.load(MinMaxScaler.class, storageName, configuration);
    categoricalEncoder = MLBuilder.load(CornerConstraintsEncoder.class, storageName, configuration);
    instance = MLBuilder.load(Adaboost.class, storageName, configuration);
    numericalScaler.transform(validationData);
    categoricalEncoder.transform(validationData);
    instance.predict(validationData);
    Map<Integer, Object> expResult = new HashMap<>();
    Map<Integer, Object> result = new HashMap<>();
    for (Map.Entry<Integer, Record> e : validationData.entries()) {
        Integer rId = e.getKey();
        Record r = e.getValue();
        expResult.put(rId, r.getY());
        result.put(rId, r.getYPredicted());
    }
    assertEquals(expResult, result);
    numericalScaler.delete();
    categoricalEncoder.delete();
    instance.delete();
    validationData.close();
}


@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.ensembleLearningResponses(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = MLBuilder.create(new DummyXYMinMaxNormalizer.TrainingParameters(), configuration);
    df.fit_transform(trainingData);
    df.save(storageName);
    BayesianEnsembleMethod instance = MLBuilder.create(new BayesianEnsembleMethod.TrainingParameters(), configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    df.denormalize(trainingData);
    trainingData.close();
    instance.close();
    df.close();
    df = MLBuilder.load(DummyXYMinMaxNormalizer.class, storageName, configuration);
    instance = MLBuilder.load(BayesianEnsembleMethod.class, storageName, configuration);
    df.transform(validationData);
    instance.predict(validationData);
    df.denormalize(validationData);
    Map<Integer, Object> expResult = new HashMap<>();
    Map<Integer, Object> result = new HashMap<>();
    for (Map.Entry<Integer, Record> e : validationData.entries()) {
        Integer rId = e.getKey();
        Record r = e.getValue();
        expResult.put(rId, r.getY());
        result.put(rId, r.getYPredicted());
    }
    assertEquals(expResult, result);
    df.delete();
    instance.delete();
    validationData.close();
}

@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.ensembleLearningResponses(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    nsParams.setScaleResponse(true);
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    numericalScaler.save(storageName);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    categoricalEncoder.save(storageName);
    BayesianEnsembleMethod instance = MLBuilder.create(new BayesianEnsembleMethod.TrainingParameters(), configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    trainingData.close();
    instance.close();
    numericalScaler.close();
    categoricalEncoder.close();
    numericalScaler = MLBuilder.load(MinMaxScaler.class, storageName, configuration);
    categoricalEncoder = MLBuilder.load(CornerConstraintsEncoder.class, storageName, configuration);
    instance = MLBuilder.load(BayesianEnsembleMethod.class, storageName, configuration);
    numericalScaler.transform(validationData);
    categoricalEncoder.transform(validationData);
    instance.predict(validationData);
    Map<Integer, Object> expResult = new HashMap<>();
    Map<Integer, Object> result = new HashMap<>();
    for (Map.Entry<Integer, Record> e : validationData.entries()) {
        Integer rId = e.getKey();
        Record r = e.getValue();
        expResult.put(rId, r.getY());
        result.put(rId, r.getYPredicted());
    }
    assertEquals(expResult, result);
    numericalScaler.delete();
    categoricalEncoder.delete();
    instance.delete();
    validationData.close();
}


@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.carsCategorical(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = MLBuilder.create(new DummyXYMinMaxNormalizer.TrainingParameters(), configuration);
    df.fit_transform(trainingData);
    df.save(storageName);
    BootstrapAggregating.TrainingParameters param = new BootstrapAggregating.TrainingParameters();
    param.setMaxWeakClassifiers(5);
    MultinomialNaiveBayes.TrainingParameters trainingParameters = new MultinomialNaiveBayes.TrainingParameters();
    trainingParameters.setMultiProbabilityWeighted(true);
    param.setWeakClassifierTrainingParameters(trainingParameters);
    BootstrapAggregating instance = MLBuilder.create(param, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    df.denormalize(trainingData);
    trainingData.close();
    instance.close();
    df.close();
    df = MLBuilder.load(DummyXYMinMaxNormalizer.class, storageName, configuration);
    instance = MLBuilder.load(BootstrapAggregating.class, storageName, configuration);
    df.transform(validationData);
    instance.predict(validationData);
    df.denormalize(validationData);
    Map<Integer, Object> expResult = new HashMap<>();
    Map<Integer, Object> result = new HashMap<>();
    for (Map.Entry<Integer, Record> e : validationData.entries()) {
        Integer rId = e.getKey();
        Record r = e.getValue();
        expResult.put(rId, r.getY());
        result.put(rId, r.getYPredicted());
    }
    assertEquals(expResult, result);
    df.delete();
    instance.delete();
    validationData.close();
}

@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.carsCategorical(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    nsParams.setScaleResponse(true);
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    numericalScaler.save(storageName);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    categoricalEncoder.save(storageName);
    BootstrapAggregating.TrainingParameters param = new BootstrapAggregating.TrainingParameters();
    param.setMaxWeakClassifiers(5);
    MultinomialNaiveBayes.TrainingParameters trainingParameters = new MultinomialNaiveBayes.TrainingParameters();
    trainingParameters.setMultiProbabilityWeighted(true);
    param.setWeakClassifierTrainingParameters(trainingParameters);
    BootstrapAggregating instance = MLBuilder.create(param, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    trainingData.close();
    instance.close();
    numericalScaler.close();
    categoricalEncoder.close();
    numericalScaler = MLBuilder.load(MinMaxScaler.class, storageName, configuration);
    categoricalEncoder = MLBuilder.load(CornerConstraintsEncoder.class, storageName, configuration);
    instance = MLBuilder.load(BootstrapAggregating.class, storageName, configuration);
    numericalScaler.transform(validationData);
    categoricalEncoder.transform(validationData);
    instance.predict(validationData);
    Map<Integer, Object> expResult = new HashMap<>();
    Map<Integer, Object> result = new HashMap<>();
    for (Map.Entry<Integer, Record> e : validationData.entries()) {
        Integer rId = e.getKey();
        Record r = e.getValue();
        expResult.put(rId, r.getY());
        result.put(rId, r.getYPredicted());
    }
    assertEquals(expResult, result);
    numericalScaler.delete();
    categoricalEncoder.delete();
    instance.delete();
    validationData.close();
}


@Test
public void testKFoldCrossValidation() {
    logger.info("testKFoldCrossValidation");
    Configuration configuration = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.regressionMixed(configuration);
    Dataframe trainingData = data[0];
    data[1].close();
    DummyXYMinMaxNormalizer df = MLBuilder.create(new DummyXYMinMaxNormalizer.TrainingParameters(), configuration);
    df.fit_transform(trainingData);
    MatrixLinearRegression.TrainingParameters param = new MatrixLinearRegression.TrainingParameters();
    LinearRegressionMetrics vm = new Validator<>(LinearRegressionMetrics.class, configuration).validate(new KFoldSplitter(k).split(trainingData), param);
    df.denormalize(trainingData);
    double expResult = 1;
    double result = vm.getRSquare();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.close();
    trainingData.close();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("testKFoldCrossValidation");
    Configuration configuration = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.regressionMixed(configuration);
    Dataframe trainingData = data[0];
    data[1].close();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    nsParams.setScaleResponse(true);
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    MatrixLinearRegression.TrainingParameters param = new MatrixLinearRegression.TrainingParameters();
    LinearRegressionMetrics vm = new Validator<>(LinearRegressionMetrics.class, configuration).validate(new KFoldSplitter(k).split(trainingData), param);
    double expResult = 1;
    double result = vm.getRSquare();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    numericalScaler.close();
    categoricalEncoder.close();
    trainingData.close();
}

@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.regressionNumeric(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    XYMinMaxNormalizer df = MLBuilder.create(new XYMinMaxNormalizer.TrainingParameters(), configuration);
    df.fit_transform(trainingData);
    df.save(storageName);
    MatrixLinearRegression instance = MLBuilder.create(new MatrixLinearRegression.TrainingParameters(), configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    df.denormalize(trainingData);
    trainingData.close();
    instance.close();
    df.close();
    df = MLBuilder.load(XYMinMaxNormalizer.class, storageName, configuration);
    instance = MLBuilder.load(MatrixLinearRegression.class, storageName, configuration);
    df.transform(validationData);
    instance.predict(validationData);
    df.denormalize(validationData);
    for (Record r : validationData) {
        assertEquals(TypeInference.toDouble(r.getY()), TypeInference.toDouble(r.getYPredicted()), Constants.DOUBLE_ACCURACY_HIGH);
    }
    df.delete();
    instance.delete();
    validationData.close();
}

@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.regressionNumeric(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    nsParams.setScaleResponse(true);
    MinMaxScaler scaler = MLBuilder.create(nsParams, configuration);
    scaler.fit_transform(trainingData);
    scaler.save(storageName);
    MatrixLinearRegression instance = MLBuilder.create(new MatrixLinearRegression.TrainingParameters(), configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    trainingData.close();
    instance.close();
    scaler.close();
    scaler = MLBuilder.load(MinMaxScaler.class, storageName, configuration);
    instance = MLBuilder.load(MatrixLinearRegression.class, storageName, configuration);
    scaler.transform(validationData);
    instance.predict(validationData);
    for (Record r : validationData) {
        assertEquals(TypeInference.toDouble(r.getY()), TypeInference.toDouble(r.getYPredicted()), Constants.DOUBLE_ACCURACY_HIGH);
    }
    scaler.delete();
    instance.delete();
    validationData.close();
}


@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.regressionNumeric(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = MLBuilder.create(new DummyXYMinMaxNormalizer.TrainingParameters(), configuration);
    df.fit_transform(trainingData);
    df.save(storageName);
    NLMS.TrainingParameters param = new NLMS.TrainingParameters();
    param.setTotalIterations(1600);
    param.setL1(0.00000001);
    NLMS instance = MLBuilder.create(param, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    df.denormalize(trainingData);
    trainingData.close();
    instance.close();
    df.close();
    df = MLBuilder.load(DummyXYMinMaxNormalizer.class, storageName, configuration);
    instance = MLBuilder.load(NLMS.class, storageName, configuration);
    df.transform(validationData);
    instance.predict(validationData);
    df.denormalize(validationData);
    for (Record r : validationData) {
        assertEquals(TypeInference.toDouble(r.getY()), TypeInference.toDouble(r.getYPredicted()), Constants.DOUBLE_ACCURACY_HIGH);
    }
    df.delete();
    instance.delete();
    validationData.close();
}

@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.regressionNumeric(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    nsParams.setScaleResponse(true);
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    numericalScaler.save(storageName);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    categoricalEncoder.save(storageName);
    NLMS.TrainingParameters param = new NLMS.TrainingParameters();
    param.setTotalIterations(1600);
    param.setL1(0.00000001);
    NLMS instance = MLBuilder.create(param, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    trainingData.close();
    instance.close();
    numericalScaler.close();
    categoricalEncoder.close();
    numericalScaler = MLBuilder.load(MinMaxScaler.class, storageName, configuration);
    categoricalEncoder = MLBuilder.load(CornerConstraintsEncoder.class, storageName, configuration);
    instance = MLBuilder.load(NLMS.class, storageName, configuration);
    numericalScaler.transform(validationData);
    categoricalEncoder.transform(validationData);
    instance.predict(validationData);
    for (Record r : validationData) {
        assertEquals(TypeInference.toDouble(r.getY()), TypeInference.toDouble(r.getYPredicted()), Constants.DOUBLE_ACCURACY_HIGH);
    }
    numericalScaler.delete();
    categoricalEncoder.delete();
    instance.delete();
    validationData.close();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("testKFoldCrossValidation");
    Configuration configuration = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.housingNumerical(configuration);
    Dataframe trainingData = data[0];
    data[1].close();
    DummyXYMinMaxNormalizer df = MLBuilder.create(new DummyXYMinMaxNormalizer.TrainingParameters(), configuration);
    df.fit_transform(trainingData);
    PCA.TrainingParameters featureSelectorParameters = new PCA.TrainingParameters();
    featureSelectorParameters.setMaxDimensions(trainingData.xColumnSize() - 1);
    featureSelectorParameters.setWhitened(false);
    featureSelectorParameters.setVariancePercentageThreshold(0.99999995);
    PCA featureSelector = MLBuilder.create(featureSelectorParameters, configuration);
    featureSelector.fit_transform(trainingData);
    featureSelector.close();
    NLMS.TrainingParameters param = new NLMS.TrainingParameters();
    param.setTotalIterations(500);
    param.setL1(0.001);
    param.setL2(0.001);
    LinearRegressionMetrics vm = new Validator<>(LinearRegressionMetrics.class, configuration).validate(new KFoldSplitter(k).split(trainingData), param);
    df.denormalize(trainingData);
    double expResult = 0.7748106446239166;
    double result = vm.getRSquare();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.close();
    trainingData.close();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("testKFoldCrossValidation");
    Configuration configuration = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.housingNumerical(configuration);
    Dataframe trainingData = data[0];
    data[1].close();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    nsParams.setScaleResponse(true);
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    PCA.TrainingParameters featureSelectorParameters = new PCA.TrainingParameters();
    featureSelectorParameters.setMaxDimensions(trainingData.xColumnSize() - 1);
    featureSelectorParameters.setWhitened(false);
    featureSelectorParameters.setVariancePercentageThreshold(0.99999995);
    PCA featureSelector = MLBuilder.create(featureSelectorParameters, configuration);
    featureSelector.fit_transform(trainingData);
    featureSelector.close();
    NLMS.TrainingParameters param = new NLMS.TrainingParameters();
    param.setTotalIterations(500);
    param.setL1(0.001);
    param.setL2(0.001);
    LinearRegressionMetrics vm = new Validator<>(LinearRegressionMetrics.class, configuration).validate(new KFoldSplitter(k).split(trainingData), param);
    double expResult = 0.7748106446239166;
    double result = vm.getRSquare();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    numericalScaler.close();
    categoricalEncoder.close();
    trainingData.close();
}


@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.regressionNumeric(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = MLBuilder.create(new DummyXYMinMaxNormalizer.TrainingParameters(), configuration);
    df.fit_transform(trainingData);
    df.save(storageName);
    StepwiseRegression.TrainingParameters param = new StepwiseRegression.TrainingParameters();
    param.setAout(0.05);
    MatrixLinearRegression.TrainingParameters trainingParams = new MatrixLinearRegression.TrainingParameters();
    param.setRegressionTrainingParameters(trainingParams);
    StepwiseRegression instance = MLBuilder.create(param, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    df.denormalize(trainingData);
    trainingData.close();
    instance.close();
    df.close();
    df = MLBuilder.load(DummyXYMinMaxNormalizer.class, storageName, configuration);
    instance = MLBuilder.load(StepwiseRegression.class, storageName, configuration);
    df.transform(validationData);
    instance.predict(validationData);
    df.denormalize(validationData);
    for (Record r : validationData) {
        Assert.assertEquals(TypeInference.toDouble(r.getY()), TypeInference.toDouble(r.getYPredicted()), Constants.DOUBLE_ACCURACY_HIGH);
    }
    df.delete();
    instance.delete();
    validationData.close();
}

@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.regressionNumeric(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    nsParams.setScaleResponse(true);
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    numericalScaler.save(storageName);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    categoricalEncoder.save(storageName);
    StepwiseRegression.TrainingParameters param = new StepwiseRegression.TrainingParameters();
    param.setAout(0.05);
    MatrixLinearRegression.TrainingParameters trainingParams = new MatrixLinearRegression.TrainingParameters();
    param.setRegressionTrainingParameters(trainingParams);
    StepwiseRegression instance = MLBuilder.create(param, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    trainingData.close();
    instance.close();
    numericalScaler.close();
    categoricalEncoder.close();
    numericalScaler = MLBuilder.load(MinMaxScaler.class, storageName, configuration);
    categoricalEncoder = MLBuilder.load(CornerConstraintsEncoder.class, storageName, configuration);
    instance = MLBuilder.load(StepwiseRegression.class, storageName, configuration);
    numericalScaler.transform(validationData);
    categoricalEncoder.transform(validationData);
    instance.predict(validationData);
    for (Record r : validationData) {
        Assert.assertEquals(TypeInference.toDouble(r.getY()), TypeInference.toDouble(r.getYPredicted()), Constants.DOUBLE_ACCURACY_HIGH);
    }
    numericalScaler.delete();
    categoricalEncoder.delete();
    instance.delete();
    validationData.close();
}


@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.carsCategorical(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = MLBuilder.create(new DummyXYMinMaxNormalizer.TrainingParameters(), configuration);
    df.fit_transform(trainingData);
    df.save(storageName);
    MultinomialNaiveBayes.TrainingParameters param = new MultinomialNaiveBayes.TrainingParameters();
    param.setMultiProbabilityWeighted(true);
    MultinomialNaiveBayes instance = MLBuilder.create(param, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    df.denormalize(trainingData);
    trainingData.close();
    instance.close();
    df.close();
    df = MLBuilder.load(DummyXYMinMaxNormalizer.class, storageName, configuration);
    instance = MLBuilder.load(MultinomialNaiveBayes.class, storageName, configuration);
    df.transform(validationData);
    instance.predict(validationData);
    df.denormalize(validationData);
    Map<Integer, Object> expResult = new HashMap<>();
    Map<Integer, Object> result = new HashMap<>();
    for (Map.Entry<Integer, Record> e : validationData.entries()) {
        Integer rId = e.getKey();
        Record r = e.getValue();
        expResult.put(rId, r.getY());
        result.put(rId, r.getYPredicted());
    }
    assertEquals(expResult, result);
    df.delete();
    instance.delete();
    validationData.close();
}

@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.carsCategorical(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    numericalScaler.save(storageName);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    categoricalEncoder.save(storageName);
    MultinomialNaiveBayes.TrainingParameters param = new MultinomialNaiveBayes.TrainingParameters();
    param.setMultiProbabilityWeighted(true);
    MultinomialNaiveBayes instance = MLBuilder.create(param, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    trainingData.close();
    instance.close();
    numericalScaler.close();
    categoricalEncoder.close();
    numericalScaler = MLBuilder.load(MinMaxScaler.class, storageName, configuration);
    categoricalEncoder = MLBuilder.load(CornerConstraintsEncoder.class, storageName, configuration);
    instance = MLBuilder.load(MultinomialNaiveBayes.class, storageName, configuration);
    numericalScaler.transform(validationData);
    categoricalEncoder.transform(validationData);
    instance.predict(validationData);
    Map<Integer, Object> expResult = new HashMap<>();
    Map<Integer, Object> result = new HashMap<>();
    for (Map.Entry<Integer, Record> e : validationData.entries()) {
        Integer rId = e.getKey();
        Record r = e.getValue();
        expResult.put(rId, r.getY());
        result.put(rId, r.getYPredicted());
    }
    assertEquals(expResult, result);
    numericalScaler.delete();
    categoricalEncoder.delete();
    instance.delete();
    validationData.close();
}


@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.carsCategorical(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    numericalScaler.save(storageName);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    categoricalEncoder.save(storageName);
    SoftMaxRegression.TrainingParameters param = new SoftMaxRegression.TrainingParameters();
    param.setTotalIterations(2000);
    param.setL2(0.001);
    SoftMaxRegression instance = MLBuilder.create(param, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    trainingData.close();
    instance.close();
    numericalScaler.close();
    categoricalEncoder.close();
    numericalScaler = MLBuilder.load(MinMaxScaler.class, storageName, configuration);
    categoricalEncoder = MLBuilder.load(CornerConstraintsEncoder.class, storageName, configuration);
    instance = MLBuilder.load(SoftMaxRegression.class, storageName, configuration);
    numericalScaler.transform(validationData);
    categoricalEncoder.transform(validationData);
    instance.predict(validationData);
    Map<Integer, Object> expResult = new HashMap<>();
    Map<Integer, Object> result = new HashMap<>();
    for (Map.Entry<Integer, Record> e : validationData.entries()) {
        Integer rId = e.getKey();
        Record r = e.getValue();
        expResult.put(rId, r.getY());
        result.put(rId, r.getYPredicted());
    }
    assertEquals(expResult, result);
    numericalScaler.delete();
    categoricalEncoder.delete();
    instance.delete();
    validationData.close();
}


@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.carsCategorical(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    numericalScaler.save(storageName);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    categoricalEncoder.save(storageName);
    SupportVectorMachine.TrainingParameters param = new SupportVectorMachine.TrainingParameters();
    param.getSvmParameter().kernel_type = svm_parameter.RBF;
    SupportVectorMachine instance = MLBuilder.create(param, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    trainingData.close();
    instance.close();
    numericalScaler.close();
    categoricalEncoder.close();
    numericalScaler = MLBuilder.load(MinMaxScaler.class, storageName, configuration);
    categoricalEncoder = MLBuilder.load(CornerConstraintsEncoder.class, storageName, configuration);
    instance = MLBuilder.load(SupportVectorMachine.class, storageName, configuration);
    numericalScaler.transform(validationData);
    categoricalEncoder.transform(validationData);
    instance.predict(validationData);
    Map<Integer, Object> expResult = new HashMap<>();
    Map<Integer, Object> result = new HashMap<>();
    for (Map.Entry<Integer, Record> e : validationData.entries()) {
        Integer rId = e.getKey();
        Record r = e.getValue();
        expResult.put(rId, r.getY());
        result.put(rId, r.getYPredicted());
    }
    assertEquals(expResult, result);
    numericalScaler.delete();
    categoricalEncoder.delete();
    instance.delete();
    validationData.close();
}


@Test
public void testKFoldCrossValidation() {
    logger.info("testKFoldCrossValidation");
    Configuration configuration = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.heartDiseaseClusters(configuration);
    Dataframe trainingData = data[0];
    data[1].close();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    HierarchicalAgglomerative.TrainingParameters param = new HierarchicalAgglomerative.TrainingParameters();
    param.setDistanceMethod(HierarchicalAgglomerative.TrainingParameters.Distance.EUCLIDIAN);
    param.setLinkageMethod(HierarchicalAgglomerative.TrainingParameters.Linkage.COMPLETE);
    param.setMinClustersThreshold(2);
    param.setMaxDistanceThreshold(Double.MAX_VALUE);
    ClusteringMetrics vm = new Validator<>(ClusteringMetrics.class, configuration).validate(new KFoldSplitter(k).split(trainingData), param);
    double expResult = 0.7666666666666667;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    numericalScaler.close();
    categoricalEncoder.close();
    trainingData.close();
}

@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.heartDiseaseClusters(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    numericalScaler.save(storageName);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    categoricalEncoder.save(storageName);
    HierarchicalAgglomerative.TrainingParameters param = new HierarchicalAgglomerative.TrainingParameters();
    param.setDistanceMethod(HierarchicalAgglomerative.TrainingParameters.Distance.EUCLIDIAN);
    param.setLinkageMethod(HierarchicalAgglomerative.TrainingParameters.Linkage.COMPLETE);
    param.setMinClustersThreshold(2);
    param.setMaxDistanceThreshold(Double.MAX_VALUE);
    HierarchicalAgglomerative instance = MLBuilder.create(param, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    trainingData.close();
    instance.close();
    numericalScaler.close();
    categoricalEncoder.close();
    numericalScaler = MLBuilder.load(MinMaxScaler.class, storageName, configuration);
    categoricalEncoder = MLBuilder.load(CornerConstraintsEncoder.class, storageName, configuration);
    instance = MLBuilder.load(HierarchicalAgglomerative.class, storageName, configuration);
    numericalScaler.transform(validationData);
    categoricalEncoder.transform(validationData);
    instance.predict(validationData);
    ClusteringMetrics vm = new ClusteringMetrics(validationData);
    double expResult = 1.0;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    numericalScaler.delete();
    categoricalEncoder.delete();
    instance.delete();
    validationData.close();
}


@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.heartDiseaseClusters(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    numericalScaler.save(storageName);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    categoricalEncoder.save(storageName);
    Kmeans.TrainingParameters param = new Kmeans.TrainingParameters();
    param.setK(2);
    param.setMaxIterations(200);
    param.setInitializationMethod(Kmeans.TrainingParameters.Initialization.FORGY);
    param.setDistanceMethod(Kmeans.TrainingParameters.Distance.EUCLIDIAN);
    param.setWeighted(false);
    param.setCategoricalGamaMultiplier(1.0);
    param.setSubsetFurthestFirstcValue(2.0);
    Kmeans instance = MLBuilder.create(param, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    trainingData.close();
    instance.close();
    numericalScaler.close();
    categoricalEncoder.close();
    numericalScaler = MLBuilder.load(MinMaxScaler.class, storageName, configuration);
    categoricalEncoder = MLBuilder.load(CornerConstraintsEncoder.class, storageName, configuration);
    instance = MLBuilder.load(Kmeans.class, storageName, configuration);
    numericalScaler.transform(validationData);
    categoricalEncoder.transform(validationData);
    instance.predict(validationData);
    ClusteringMetrics vm = new ClusteringMetrics(validationData);
    double expResult = 1.0;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    numericalScaler.delete();
    categoricalEncoder.delete();
    instance.delete();
    validationData.close();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("testKFoldCrossValidation");
    Configuration configuration = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.heartDiseaseClusters(configuration);
    Dataframe trainingData = data[0];
    data[1].close();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    Kmeans.TrainingParameters param = new Kmeans.TrainingParameters();
    param.setK(2);
    param.setMaxIterations(200);
    param.setInitializationMethod(Kmeans.TrainingParameters.Initialization.FORGY);
    param.setDistanceMethod(Kmeans.TrainingParameters.Distance.EUCLIDIAN);
    param.setWeighted(false);
    param.setCategoricalGamaMultiplier(1.0);
    param.setSubsetFurthestFirstcValue(2.0);
    ClusteringMetrics vm = new Validator<>(ClusteringMetrics.class, configuration).validate(new KFoldSplitter(k).split(trainingData), param);
    double expResult = 0.7888888888888889;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    numericalScaler.close();
    categoricalEncoder.close();
    trainingData.close();
}


@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.carsCategorical(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    numericalScaler.save(storageName);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    categoricalEncoder.save(storageName);
    Adaboost.TrainingParameters param = new Adaboost.TrainingParameters();
    param.setMaxWeakClassifiers(5);
    MultinomialNaiveBayes.TrainingParameters trainingParameters = new MultinomialNaiveBayes.TrainingParameters();
    trainingParameters.setMultiProbabilityWeighted(true);
    param.setWeakClassifierTrainingParameters(trainingParameters);
    Adaboost instance = MLBuilder.create(param, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    instance.close();
    numericalScaler.close();
    categoricalEncoder.close();
    numericalScaler = MLBuilder.load(MinMaxScaler.class, storageName, configuration);
    categoricalEncoder = MLBuilder.load(CornerConstraintsEncoder.class, storageName, configuration);
    instance = MLBuilder.load(Adaboost.class, storageName, configuration);
    numericalScaler.transform(validationData);
    categoricalEncoder.transform(validationData);
    instance.predict(validationData);
    Map<Integer, Object> expResult = new HashMap<>();
    Map<Integer, Object> result = new HashMap<>();
    for (Map.Entry<Integer, Record> e : validationData.entries()) {
        Integer rId = e.getKey();
        Record r = e.getValue();
        expResult.put(rId, r.getY());
        result.put(rId, r.getYPredicted());
    }
    assertEquals(expResult, result);
    numericalScaler.delete();
    categoricalEncoder.delete();
    instance.delete();
    validationData.close();
}


@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.ensembleLearningResponses(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    numericalScaler.save(storageName);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    categoricalEncoder.save(storageName);
    BayesianEnsembleMethod instance = MLBuilder.create(new BayesianEnsembleMethod.TrainingParameters(), configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    trainingData.close();
    instance.close();
    numericalScaler.close();
    categoricalEncoder.close();
    numericalScaler = MLBuilder.load(MinMaxScaler.class, storageName, configuration);
    categoricalEncoder = MLBuilder.load(CornerConstraintsEncoder.class, storageName, configuration);
    instance = MLBuilder.load(BayesianEnsembleMethod.class, storageName, configuration);
    numericalScaler.transform(validationData);
    categoricalEncoder.transform(validationData);
    instance.predict(validationData);
    Map<Integer, Object> expResult = new HashMap<>();
    Map<Integer, Object> result = new HashMap<>();
    for (Map.Entry<Integer, Record> e : validationData.entries()) {
        Integer rId = e.getKey();
        Record r = e.getValue();
        expResult.put(rId, r.getY());
        result.put(rId, r.getYPredicted());
    }
    assertEquals(expResult, result);
    numericalScaler.delete();
    categoricalEncoder.delete();
    instance.delete();
    validationData.close();
}


@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.carsCategorical(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    numericalScaler.save(storageName);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    categoricalEncoder.save(storageName);
    BootstrapAggregating.TrainingParameters param = new BootstrapAggregating.TrainingParameters();
    param.setMaxWeakClassifiers(5);
    MultinomialNaiveBayes.TrainingParameters trainingParameters = new MultinomialNaiveBayes.TrainingParameters();
    trainingParameters.setMultiProbabilityWeighted(true);
    param.setWeakClassifierTrainingParameters(trainingParameters);
    BootstrapAggregating instance = MLBuilder.create(param, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    trainingData.close();
    instance.close();
    numericalScaler.close();
    categoricalEncoder.close();
    numericalScaler = MLBuilder.load(MinMaxScaler.class, storageName, configuration);
    categoricalEncoder = MLBuilder.load(CornerConstraintsEncoder.class, storageName, configuration);
    instance = MLBuilder.load(BootstrapAggregating.class, storageName, configuration);
    numericalScaler.transform(validationData);
    categoricalEncoder.transform(validationData);
    instance.predict(validationData);
    Map<Integer, Object> expResult = new HashMap<>();
    Map<Integer, Object> result = new HashMap<>();
    for (Map.Entry<Integer, Record> e : validationData.entries()) {
        Integer rId = e.getKey();
        Record r = e.getValue();
        expResult.put(rId, r.getY());
        result.put(rId, r.getYPredicted());
    }
    assertEquals(expResult, result);
    numericalScaler.delete();
    categoricalEncoder.delete();
    instance.delete();
    validationData.close();
}


@Test
public void testKFoldCrossValidation() {
    logger.info("testKFoldCrossValidation");
    Configuration configuration = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.regressionMixed(configuration);
    Dataframe trainingData = data[0];
    data[1].close();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    MatrixLinearRegression.TrainingParameters param = new MatrixLinearRegression.TrainingParameters();
    LinearRegressionMetrics vm = new Validator<>(LinearRegressionMetrics.class, configuration).validate(new KFoldSplitter(k).split(trainingData), param);
    double expResult = 1;
    double result = vm.getRSquare();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    numericalScaler.close();
    categoricalEncoder.close();
    trainingData.close();
}


@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.regressionNumeric(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    numericalScaler.save(storageName);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    categoricalEncoder.save(storageName);
    NLMS.TrainingParameters param = new NLMS.TrainingParameters();
    param.setTotalIterations(1600);
    param.setL1(0.00000001);
    NLMS instance = MLBuilder.create(param, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    trainingData.close();
    instance.close();
    numericalScaler.close();
    categoricalEncoder.close();
    numericalScaler = MLBuilder.load(MinMaxScaler.class, storageName, configuration);
    categoricalEncoder = MLBuilder.load(CornerConstraintsEncoder.class, storageName, configuration);
    instance = MLBuilder.load(NLMS.class, storageName, configuration);
    numericalScaler.transform(validationData);
    categoricalEncoder.transform(validationData);
    instance.predict(validationData);
    for (Record r : validationData) {
        assertEquals(TypeInference.toDouble(r.getY()), TypeInference.toDouble(r.getYPredicted()), Constants.DOUBLE_ACCURACY_HIGH);
    }
    numericalScaler.delete();
    categoricalEncoder.delete();
    instance.delete();
    validationData.close();
}


@Test
public void testPredict() {
    logger.info("testPredict");
    Configuration configuration = Configuration.getConfiguration();
    Dataframe[] data = Datasets.regressionNumeric(configuration);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String storageName = this.getClass().getSimpleName();
    MinMaxScaler.TrainingParameters nsParams = new MinMaxScaler.TrainingParameters();
    MinMaxScaler numericalScaler = MLBuilder.create(nsParams, configuration);
    numericalScaler.fit_transform(trainingData);
    numericalScaler.save(storageName);
    CornerConstraintsEncoder.TrainingParameters ceParams = new CornerConstraintsEncoder.TrainingParameters();
    CornerConstraintsEncoder categoricalEncoder = MLBuilder.create(ceParams, configuration);
    categoricalEncoder.fit_transform(trainingData);
    categoricalEncoder.save(storageName);
    StepwiseRegression.TrainingParameters param = new StepwiseRegression.TrainingParameters();
    param.setAout(0.05);
    MatrixLinearRegression.TrainingParameters trainingParams = new MatrixLinearRegression.TrainingParameters();
    param.setRegressionTrainingParameters(trainingParams);
    StepwiseRegression instance = MLBuilder.create(param, configuration);
    instance.fit(trainingData);
    instance.save(storageName);
    trainingData.close();
    instance.close();
    numericalScaler.close();
    categoricalEncoder.close();
    numericalScaler = MLBuilder.load(MinMaxScaler.class, storageName, configuration);
    categoricalEncoder = MLBuilder.load(CornerConstraintsEncoder.class, storageName, configuration);
    instance = MLBuilder.load(StepwiseRegression.class, storageName, configuration);
    numericalScaler.transform(validationData);
    categoricalEncoder.transform(validationData);
    instance.predict(validationData);
    for (Record r : validationData) {
        Assert.assertEquals(TypeInference.toDouble(r.getY()), TypeInference.toDouble(r.getYPredicted()), Constants.DOUBLE_ACCURACY_HIGH);
    }
    numericalScaler.delete();
    categoricalEncoder.delete();
    instance.delete();
    validationData.close();
}


@Test
public void testMbr() {
    Rectangle r1 = Geometries.rectangle(0, 1, 3, 5);
    Rectangle r2 = Geometries.rectangle(1, 2, 4, 6);
    @SuppressWarnings("unchecked")
    Rectangle r = new LeafDefault<Object, Rectangle>(Arrays.asList(Entries.entry(new Object(), r1), Entries.entry(new Object(), r2)), context).geometry().mbr();
    assertEquals(r1.add(r2), r);
}

@Test
public void testMbr() {
    Rectangle r1 = Geometries.rectangle(0d, 1, 3, 5);
    Rectangle r2 = Geometries.rectangle(1d, 2, 4, 6);
    @SuppressWarnings("unchecked")
    Rectangle r = new LeafDefault<Object, Rectangle>(Arrays.asList(Entries.entry(new Object(), r1), Entries.entry(new Object(), r2)), context).geometry().mbr();
    assertEquals(r1.add(r2), r);
}

@Override
public Rectangle add(Rectangle r) {
    if (r.isDoublePrecision()) {
        return RectangleDoubleImpl.create(min(x1, r.x1()), min(y1, r.y1()), max(x2, r.x2()), max(y2, r.y2()));
    } else {
        return RectangleDoubleImpl.create(min(x1, r.x1()), min(y1, r.y1()), max(x2, r.x2()), max(y2, r.y2()));
    }
}

@Override
public Rectangle add(Rectangle r) {
    if (r.isDoublePrecision()) {
        return RectangleDoubleImpl.create(min(x1, r.x1()), min(y1, r.y1()), max(x2, r.x2()), max(y2, r.y2()));
    } else if (r instanceof Point) {
        Point p = (Point) r;
        return RectangleImpl.create(min(x1, p.x()), min(y1, p.y()), max(x2, p.x()), max(y2, p.y()));
    } else {
        RectangleImpl rf = (RectangleImpl) r;
        return RectangleImpl.create(min(x1, rf.x1), min(y1, rf.y1), max(x2, rf.x2), max(y2, rf.y2));
    }
}


@Test
public void testMbr() {
    Point p = Geometries.point(1, 2);
    Rectangle r = Geometries.rectangle(1, 2, 1, 2);
    assertEquals(r, p.mbr());
}

@Test
public void testMbr() {
    Point p = Geometries.point(1, 2);
    Point p2 = Geometries.point(1, 2);
    assertEquals(p, p2);
}

@Override
public Rectangle mbr() {
    return mbr;
}

@Override
public Rectangle mbr() {
    return this;
}

@Test
public void testHashCode() {
    Point p = Geometries.point(1, 2);
    assertEquals(-1056041056, p.hashCode());
}

@Test
public void testHashCode() {
    Point p = Geometries.point(1, 2);
    assertEquals(-260045887, p.hashCode());
}

@Override
public int hashCode() {
    return Objects.hashCode(mbr);
}

@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + Float.floatToIntBits(x);
    result = prime * result + Float.floatToIntBits(y);
    return result;
}


@Test
public void testRTreeRootMbrWhenRTreeNonEmpty() {
    Optional<Rectangle> r = RTree.<Integer, Point>create().add(1, point(1, 1)).add(2, point(2, 2)).mbr();
    assertEquals(Geometries.rectangle(1, 1, 2, 2), r.get());
}

@Test
public void testRTreeRootMbrWhenRTreeNonEmpty() {
    Optional<Rectangle> r = RTree.<Integer, Point>create().add(1, point(1, 1)).add(2, point(2, 2)).mbr();
    assertEquals(Geometries.rectangle(1d, 1, 2, 2), r.get());
}

public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
    return RectangleImpl.create(x1, y1, x2, y2);
}

public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
    return rectangleDouble(x1, y1, x2, y2);
}


@Test
public void GenerateCode_SomeAttributesWithValueNone() {
    Attribute[] attributes = new Attribute[] { NONE, BLUE_TEXT, NONE };
    String code = Ansi.generateCode(attributes);
    String expectedCode = PREFIX + attributes[1] + POSTFIX;
    assertThat(code, equalTo(expectedCode));
    int suffixIndex = code.lastIndexOf(POSTFIX);
    assertThat("Code ending in semicolon does not show color", code.charAt(suffixIndex - 1), is(not(';')));
}

@Test
public void GenerateCode_SomeAttributesWithValueNone() {
    Attribute[] attributes = new Attribute[] { NONE(), BLUE_TEXT(), NONE() };
    String code = Ansi.generateCode(attributes);
    String expectedCode = PREFIX + attributes[1] + POSTFIX;
    assertThat(code, equalTo(expectedCode));
    int suffixIndex = code.lastIndexOf(POSTFIX);
    assertThat("Code ending in semicolon does not show color", code.charAt(suffixIndex - 1), is(not(';')));
}

@Override
public String toString() {
    return getCode();
}

@Test
public void GenerateCode_OneAttribute() {
    Attribute[] attributes = new Attribute[] { STRIKETHROUGH };
    String code = Ansi.generateCode(attributes);
    String expectedCode = PREFIX + attributes[0] + POSTFIX;
    assertThat(code, equalTo(expectedCode));
}

@Test
public void GenerateCode_OneAttribute() {
    Attribute[] attributes = new Attribute[] { STRIKETHROUGH() };
    String code = Ansi.generateCode(attributes);
    String expectedCode = PREFIX + attributes[0] + POSTFIX;
    assertThat(code, equalTo(expectedCode));
}

@Test
public void GenerateCode_MultipleAttributes_HandlesMultipleParams() {
    Attribute firstAttribute = UNDERLINE;
    Attribute secondAttribute = GREEN_TEXT;
    String code = Ansi.generateCode(firstAttribute, secondAttribute);
    String expectedCode = PREFIX + firstAttribute + SEPARATOR + secondAttribute + POSTFIX;
    assertThat(code, equalTo(expectedCode));
}

@Test
public void GenerateCode_MultipleAttributes_HandlesMultipleParams() {
    Attribute firstAttribute = UNDERLINE();
    Attribute secondAttribute = GREEN_TEXT();
    String code = Ansi.generateCode(firstAttribute, secondAttribute);
    String expectedCode = PREFIX + firstAttribute + SEPARATOR + secondAttribute + POSTFIX;
    assertThat(code, equalTo(expectedCode));
}

@Test
public void Colorize_TextWithSingleLine() {
    Attribute[] attributes = new Attribute[] { GREEN_BACK };
    String text = createTextLine();
    String formattedText = Ansi.colorize(text, attributes);
    String expectedCode = Ansi.generateCode(attributes);
    assertThat("Format must be cleared before changing line, to avoid format spillage", formattedText, endsWith(Ansi.RESET + NEWLINE));
}

@Test
public void Colorize_TextWithSingleLine() {
    Attribute[] attributes = new Attribute[] { GREEN_BACK() };
    String text = createTextLine();
    String formattedText = Ansi.colorize(text, attributes);
    String expectedCode = Ansi.generateCode(attributes);
    assertThat("Format must be cleared before changing line, to avoid format spillage", formattedText, endsWith(Ansi.RESET + NEWLINE));
}

public static Attribute GREEN_BACK() {
    return new SimpleAttribute("42");
}

@Test
public void GenerateCode_MultipleAttributesWithValueNone() {
    Attribute[] attributes = new Attribute[] { NONE, NONE, NONE };
    String code = Ansi.generateCode(attributes);
    String expectedCode = PREFIX + POSTFIX;
    assertThat(code, equalTo(expectedCode));
}

@Test
public void GenerateCode_MultipleAttributesWithValueNone() {
    Attribute[] attributes = new Attribute[] { NONE(), NONE(), NONE() };
    String code = Ansi.generateCode(attributes);
    String expectedCode = PREFIX + POSTFIX;
    assertThat(code, equalTo(expectedCode));
}

public static Attribute NONE() {
    return new SimpleAttribute("");
}

@Test
public void Colorize_TextWithoutLines() {
    Attribute[] attributes = new Attribute[] { YELLOW_BACK };
    String text = createText();
    String formattedText = Ansi.colorize(text, attributes);
    String expectedCode = Ansi.generateCode(attributes);
    assertThat(formattedText, startsWith(expectedCode));
    assertThat("Message should clear its format", formattedText, endsWith(Ansi.RESET));
}

@Test
public void Colorize_TextWithoutLines() {
    Attribute[] attributes = new Attribute[] { YELLOW_BACK() };
    String text = createText();
    String formattedText = Ansi.colorize(text, attributes);
    String expectedCode = Ansi.generateCode(attributes);
    assertThat(formattedText, startsWith(expectedCode));
    assertThat("Message should clear its format", formattedText, endsWith(Ansi.RESET));
}

public static Attribute YELLOW_BACK() {
    return new SimpleAttribute("43");
}

@Test
public void GenerateCode_MultipleAttributes_HandlesAnsiFormat() {
    AnsiFormat attributes = new AnsiFormat(DIM, CYAN_TEXT);
    String code = Ansi.generateCode(attributes);
    String expectedCode = PREFIX + DIM + SEPARATOR + CYAN_TEXT + POSTFIX;
    assertThat(code, equalTo(expectedCode));
}

@Test
public void GenerateCode_MultipleAttributes_HandlesAnsiFormat() {
    AnsiFormat attributes = new AnsiFormat(DIM(), CYAN_TEXT());
    String code = Ansi.generateCode(attributes);
    String expectedCode = PREFIX + DIM() + SEPARATOR + CYAN_TEXT() + POSTFIX;
    assertThat(code, equalTo(expectedCode));
}

@Test
public void Colorize_ConflictingAttributes_UsesTheLast() {
    Attribute[] attributes = new Attribute[] { BLACK_BACK, WHITE_BACK, BLUE_BACK };
    String text = "This text will have a blue back";
    String formattedText = Ansi.colorize(text, attributes);
    String expectedCode = Ansi.generateCode(attributes);
    assertThat(formattedText, startsWith(expectedCode));
    assertThat("Message should clear its format", formattedText, endsWith(Ansi.RESET));
}

@Test
public void Colorize_ConflictingAttributes_UsesTheLast() {
    Attribute[] attributes = new Attribute[] { BLACK_BACK(), WHITE_BACK(), BLUE_BACK() };
    String text = "This text will have a blue back";
    String formattedText = Ansi.colorize(text, attributes);
    String expectedCode = Ansi.generateCode(attributes);
    assertThat(formattedText, startsWith(expectedCode));
    assertThat("Message should clear its format", formattedText, endsWith(Ansi.RESET));
}

public static Attribute BLUE_BACK() {
    return new SimpleAttribute("44");
}

@Test
public void GenerateCode_MultipleAttributes_HandlesArray() {
    Attribute[] attributes = new Attribute[] { DIM, CYAN_TEXT };
    String code = Ansi.generateCode(attributes);
    String expectedCode = PREFIX + attributes[0] + SEPARATOR + attributes[1] + POSTFIX;
    assertThat(code, equalTo(expectedCode));
}

@Test
public void GenerateCode_MultipleAttributes_HandlesArray() {
    Attribute[] attributes = new Attribute[] { DIM(), CYAN_TEXT() };
    String code = Ansi.generateCode(attributes);
    String expectedCode = PREFIX + attributes[0] + SEPARATOR + attributes[1] + POSTFIX;
    assertThat(code, equalTo(expectedCode));
}

@Test
public void Colorize_TextWithMultiplesLines() {
    Attribute[] attributes = new Attribute[] { RED_BACK };
    String text1 = createTextWithId(1), text2 = createTextWithId(2);
    String fullText = text1 + NEWLINE + text2 + NEWLINE;
    String formattedText = Ansi.colorize(fullText, attributes);
    String expectedCode = Ansi.generateCode(attributes);
    assertThat("Middle lines preserve format", formattedText, containsString(expectedCode + text2 + Ansi.RESET));
    assertThat(formattedText, endsWith(Ansi.RESET + NEWLINE));
}

@Test
public void Colorize_TextWithMultiplesLines() {
    Attribute[] attributes = new Attribute[] { RED_BACK() };
    String text1 = createTextWithId(1), text2 = createTextWithId(2);
    String fullText = text1 + NEWLINE + text2 + NEWLINE;
    String formattedText = Ansi.colorize(fullText, attributes);
    String expectedCode = Ansi.generateCode(attributes);
    assertThat("Middle lines preserve format", formattedText, containsString(expectedCode + text2 + Ansi.RESET));
    assertThat(formattedText, endsWith(Ansi.RESET + NEWLINE));
}

public static Attribute RED_BACK() {
    return new SimpleAttribute("41");
}