@Test
public void testTrainAndValidate() {
    logger.info("testTrainAndValidate");
    Configuration conf = Configuration.getConfiguration();
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String dbName = this.getClass().getSimpleName();
    Modeler instance = new Modeler(dbName, conf);
    Modeler.TrainingParameters trainingParameters = new Modeler.TrainingParameters();
    trainingParameters.setModelerClass(MultinomialNaiveBayes.class);
    MultinomialNaiveBayes.TrainingParameters modelTrainingParameters = new MultinomialNaiveBayes.TrainingParameters();
    modelTrainingParameters.setMultiProbabilityWeighted(true);
    trainingParameters.setModelerTrainingParameters(modelTrainingParameters);
    trainingParameters.setDataTransformerClass(DummyXMinMaxNormalizer.class);
    DummyXMinMaxNormalizer.TrainingParameters dtParams = new DummyXMinMaxNormalizer.TrainingParameters();
    trainingParameters.setDataTransformerTrainingParameters(dtParams);
    trainingParameters.setFeatureSelectorClass(null);
    trainingParameters.setFeatureSelectorTrainingParameters(null);
    instance.fit(trainingData, trainingParameters);
    MultinomialNaiveBayes.ValidationMetrics vm = (MultinomialNaiveBayes.ValidationMetrics) instance.validate(trainingData);
    instance.setValidationMetrics(vm);
    double expResult2 = 0.8;
    Assert.assertEquals(expResult2, vm.getMacroF1(), Constants.DOUBLE_ACCURACY_HIGH);
    instance.close();
    logger.info("validate");
    instance = new Modeler(dbName, conf);
    instance.validate(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);
    instance.delete();
    trainingData.delete();
    validationData.delete();
}

@Test
public void testTrainAndValidate() {
    logger.info("testTrainAndValidate");
    Configuration conf = Configuration.getConfiguration();
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String dbName = this.getClass().getSimpleName();
    Modeler instance = new Modeler(dbName, conf);
    Modeler.TrainingParameters trainingParameters = new Modeler.TrainingParameters();
    trainingParameters.setModelerClass(MultinomialNaiveBayes.class);
    MultinomialNaiveBayes.TrainingParameters modelTrainingParameters = new MultinomialNaiveBayes.TrainingParameters();
    modelTrainingParameters.setMultiProbabilityWeighted(true);
    trainingParameters.setModelerTrainingParameters(modelTrainingParameters);
    trainingParameters.setDataTransformerClass(DummyXMinMaxNormalizer.class);
    DummyXMinMaxNormalizer.TrainingParameters dtParams = new DummyXMinMaxNormalizer.TrainingParameters();
    trainingParameters.setDataTransformerTrainingParameters(dtParams);
    trainingParameters.setFeatureSelectorClass(null);
    trainingParameters.setFeatureSelectorTrainingParameters(null);
    instance.fit(trainingData, trainingParameters);
    instance.predict(trainingData);
    ClassificationMetrics vm = new ClassificationMetrics(trainingData);
    double expResult2 = 0.8;
    assertEquals(expResult2, vm.getMacroF1(), Constants.DOUBLE_ACCURACY_HIGH);
    instance.close();
    logger.info("validate");
    instance = new Modeler(dbName, conf);
    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);
    instance.delete();
    trainingData.delete();
    validationData.delete();
}


@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    BernoulliNaiveBayes instance = new BernoulliNaiveBayes(dbName, conf);
    BernoulliNaiveBayes.TrainingParameters param = new BernoulliNaiveBayes.TrainingParameters();
    ClassifierValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6631318681318682;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    BernoulliNaiveBayes instance = new BernoulliNaiveBayes(dbName, conf);
    BernoulliNaiveBayes.TrainingParameters param = new BernoulliNaiveBayes.TrainingParameters();
    BernoulliNaiveBayes.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6631318681318682;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}

@Override
public void delete() {
    knowledgeBase.delete();
}

@Override
public void delete() {
    kb().delete();
}


@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    BinarizedNaiveBayes instance = new BinarizedNaiveBayes(dbName, conf);
    BinarizedNaiveBayes.TrainingParameters param = new BinarizedNaiveBayes.TrainingParameters();
    ClassifierValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6631318681318682;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    BinarizedNaiveBayes instance = new BinarizedNaiveBayes(dbName, conf);
    BinarizedNaiveBayes.TrainingParameters param = new BinarizedNaiveBayes.TrainingParameters();
    BinarizedNaiveBayes.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6631318681318682;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}


@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    MaximumEntropy instance = new MaximumEntropy(dbName, conf);
    MaximumEntropy.TrainingParameters param = new MaximumEntropy.TrainingParameters();
    param.setTotalIterations(10);
    ClassifierValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6051098901098901;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    MaximumEntropy instance = new MaximumEntropy(dbName, conf);
    MaximumEntropy.TrainingParameters param = new MaximumEntropy.TrainingParameters();
    param.setTotalIterations(10);
    MaximumEntropy.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6051098901098901;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}


@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    MultinomialNaiveBayes instance = new MultinomialNaiveBayes(dbName, conf);
    MultinomialNaiveBayes.TrainingParameters param = new MultinomialNaiveBayes.TrainingParameters();
    param.setMultiProbabilityWeighted(true);
    ClassifierValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6631318681318682;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    MultinomialNaiveBayes instance = new MultinomialNaiveBayes(dbName, conf);
    MultinomialNaiveBayes.TrainingParameters param = new MultinomialNaiveBayes.TrainingParameters();
    param.setMultiProbabilityWeighted(true);
    MultinomialNaiveBayes.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6631318681318682;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}


@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.winesOrdinal(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    DummyXMinMaxNormalizer df = new DummyXMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new DummyXMinMaxNormalizer.TrainingParameters());
    OrdinalRegression instance = new OrdinalRegression(dbName, conf);
    OrdinalRegression.TrainingParameters param = new OrdinalRegression.TrainingParameters();
    param.setTotalIterations(100);
    param.setL2(0.001);
    ClassifierValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    df.denormalize(trainingData);
    double expResult = 0.9823403146614675;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.winesOrdinal(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    DummyXMinMaxNormalizer df = new DummyXMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new DummyXMinMaxNormalizer.TrainingParameters());
    OrdinalRegression instance = new OrdinalRegression(dbName, conf);
    OrdinalRegression.TrainingParameters param = new OrdinalRegression.TrainingParameters();
    param.setTotalIterations(100);
    param.setL2(0.001);
    OrdinalRegression.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    df.denormalize(trainingData);
    double expResult = 0.9823403146614675;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
}

public void denormalize(Dataframe data) {
    logger.info("denormalize()");
    knowledgeBase.load();
    _denormalize(data);
}

public void denormalize(Dataframe data) {
    logger.info("denormalize()");
    kb().load();
    _denormalize(data);
}


@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    XMinMaxNormalizer df = new XMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new XMinMaxNormalizer.TrainingParameters());
    SoftMaxRegression instance = new SoftMaxRegression(dbName, conf);
    SoftMaxRegression.TrainingParameters param = new SoftMaxRegression.TrainingParameters();
    param.setTotalIterations(30);
    param.setL1(0.0001);
    param.setL2(0.0001);
    ClassifierValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    df.denormalize(trainingData);
    double expResult = 0.7557492507492508;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    XMinMaxNormalizer df = new XMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new XMinMaxNormalizer.TrainingParameters());
    SoftMaxRegression instance = new SoftMaxRegression(dbName, conf);
    SoftMaxRegression.TrainingParameters param = new SoftMaxRegression.TrainingParameters();
    param.setTotalIterations(30);
    param.setL1(0.0001);
    param.setL2(0.0001);
    SoftMaxRegression.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    df.denormalize(trainingData);
    double expResult = 0.7557492507492508;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
}


@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    SupportVectorMachine instance = new SupportVectorMachine(dbName, conf);
    SupportVectorMachine.TrainingParameters param = new SupportVectorMachine.TrainingParameters();
    param.getSvmParameter().kernel_type = svm_parameter.LINEAR;
    ClassifierValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6473992673992675;
    double result = vm.getMacroF1();
    Assert.assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    SupportVectorMachine instance = new SupportVectorMachine(dbName, conf);
    SupportVectorMachine.TrainingParameters param = new SupportVectorMachine.TrainingParameters();
    param.getSvmParameter().kernel_type = svm_parameter.LINEAR;
    SupportVectorMachine.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6473992673992675;
    double result = vm.getMacroF1();
    Assert.assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}


@Test
public void testValidate() {
    logger.info("validate");
    Configuration conf = Configuration.getConfiguration();
    Dataframe[] data = Datasets.gaussianClusters(conf);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String dbName = this.getClass().getSimpleName();
    GaussianDPMM instance = new GaussianDPMM(dbName, conf);
    GaussianDPMM.TrainingParameters param = new GaussianDPMM.TrainingParameters();
    param.setAlpha(0.01);
    param.setMaxIterations(100);
    param.setInitializationMethod(GaussianDPMM.TrainingParameters.Initialization.ONE_CLUSTER_PER_RECORD);
    param.setKappa0(0);
    param.setNu0(1);
    param.setMu0(new double[] { 0.0, 0.0 });
    param.setPsi0(new double[][] { { 1.0, 0.0 }, { 0.0, 1.0 } });
    instance.fit(trainingData, param);
    instance.close();
    instance = new GaussianDPMM(dbName, conf);
    ClustererValidator.ValidationMetrics vm = instance.validate(validationData);
    double expResult = 1.0;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
    validationData.delete();
}

@Test
public void testValidate() {
    logger.info("validate");
    Configuration conf = Configuration.getConfiguration();
    Dataframe[] data = Datasets.gaussianClusters(conf);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String dbName = this.getClass().getSimpleName();
    GaussianDPMM instance = new GaussianDPMM(dbName, conf);
    GaussianDPMM.TrainingParameters param = new GaussianDPMM.TrainingParameters();
    param.setAlpha(0.01);
    param.setMaxIterations(100);
    param.setInitializationMethod(GaussianDPMM.TrainingParameters.Initialization.ONE_CLUSTER_PER_RECORD);
    param.setKappa0(0);
    param.setNu0(1);
    param.setMu0(new double[] { 0.0, 0.0 });
    param.setPsi0(new double[][] { { 1.0, 0.0 }, { 0.0, 1.0 } });
    instance.fit(trainingData, param);
    instance.close();
    instance = new GaussianDPMM(dbName, conf);
    GaussianDPMM.ValidationMetrics vm = instance.validate(validationData);
    double expResult = 1.0;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
    validationData.delete();
}

public VM validate(Dataframe testingData) {
    logger.info("validate()");
    kb().load();
    VM validationMetrics = validateModel(testingData);
    return validationMetrics;
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.gaussianClusters(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    GaussianDPMM instance = new GaussianDPMM(dbName, conf);
    GaussianDPMM.TrainingParameters param = new GaussianDPMM.TrainingParameters();
    param.setAlpha(0.01);
    param.setMaxIterations(100);
    param.setInitializationMethod(GaussianDPMM.TrainingParameters.Initialization.ONE_CLUSTER_PER_RECORD);
    param.setKappa0(0);
    param.setNu0(1);
    param.setMu0(new double[] { 0.0, 0.0 });
    param.setPsi0(new double[][] { { 1.0, 0.0 }, { 0.0, 1.0 } });
    ClustererValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 1.0;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.gaussianClusters(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    GaussianDPMM instance = new GaussianDPMM(dbName, conf);
    GaussianDPMM.TrainingParameters param = new GaussianDPMM.TrainingParameters();
    param.setAlpha(0.01);
    param.setMaxIterations(100);
    param.setInitializationMethod(GaussianDPMM.TrainingParameters.Initialization.ONE_CLUSTER_PER_RECORD);
    param.setKappa0(0);
    param.setNu0(1);
    param.setMu0(new double[] { 0.0, 0.0 });
    param.setPsi0(new double[][] { { 1.0, 0.0 }, { 0.0, 1.0 } });
    GaussianDPMM.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 1.0;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}


@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.heartDiseaseClusters(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = new DummyXYMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new DummyXYMinMaxNormalizer.TrainingParameters());
    HierarchicalAgglomerative instance = new HierarchicalAgglomerative(dbName, conf);
    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);
    ClustererValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    df.denormalize(trainingData);
    double expResult = 0.7666666666666667;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.heartDiseaseClusters(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = new DummyXYMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new DummyXYMinMaxNormalizer.TrainingParameters());
    HierarchicalAgglomerative instance = new HierarchicalAgglomerative(dbName, conf);
    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.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    df.denormalize(trainingData);
    double expResult = 0.7666666666666667;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
}

@Test
public void testValidate() {
    logger.info("validate");
    Configuration conf = Configuration.getConfiguration();
    Dataframe[] data = Datasets.heartDiseaseClusters(conf);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String dbName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = new DummyXYMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new DummyXYMinMaxNormalizer.TrainingParameters());
    df.transform(validationData);
    HierarchicalAgglomerative instance = new HierarchicalAgglomerative(dbName, conf);
    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);
    instance.fit(trainingData, param);
    instance.close();
    df.close();
    df = new DummyXYMinMaxNormalizer(dbName, conf);
    instance = new HierarchicalAgglomerative(dbName, conf);
    ClustererValidator.ValidationMetrics vm = instance.validate(validationData);
    df.denormalize(trainingData);
    df.denormalize(validationData);
    double expResult = 1.0;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
    validationData.delete();
}

@Test
public void testValidate() {
    logger.info("validate");
    Configuration conf = Configuration.getConfiguration();
    Dataframe[] data = Datasets.heartDiseaseClusters(conf);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String dbName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = new DummyXYMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new DummyXYMinMaxNormalizer.TrainingParameters());
    df.transform(validationData);
    HierarchicalAgglomerative instance = new HierarchicalAgglomerative(dbName, conf);
    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);
    instance.fit(trainingData, param);
    instance.close();
    df.close();
    df = new DummyXYMinMaxNormalizer(dbName, conf);
    instance = new HierarchicalAgglomerative(dbName, conf);
    HierarchicalAgglomerative.ValidationMetrics vm = instance.validate(validationData);
    df.denormalize(trainingData);
    df.denormalize(validationData);
    double expResult = 1.0;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
    validationData.delete();
}


@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.heartDiseaseClusters(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = new DummyXYMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new DummyXYMinMaxNormalizer.TrainingParameters());
    Kmeans instance = new Kmeans(dbName, conf);
    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);
    ClustererValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    df.denormalize(trainingData);
    double expResult = 0.7888888888888889;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.heartDiseaseClusters(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = new DummyXYMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new DummyXYMinMaxNormalizer.TrainingParameters());
    Kmeans instance = new Kmeans(dbName, conf);
    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.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    df.denormalize(trainingData);
    double expResult = 0.7888888888888889;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
}

@Test
public void testValidate() {
    logger.info("validate");
    Configuration conf = Configuration.getConfiguration();
    Dataframe[] data = Datasets.heartDiseaseClusters(conf);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String dbName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = new DummyXYMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new DummyXYMinMaxNormalizer.TrainingParameters());
    df.transform(validationData);
    Kmeans instance = new Kmeans(dbName, conf);
    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);
    instance.fit(trainingData, param);
    instance.close();
    df.close();
    df = new DummyXYMinMaxNormalizer(dbName, conf);
    instance = new Kmeans(dbName, conf);
    ClustererValidator.ValidationMetrics vm = instance.validate(validationData);
    df.denormalize(trainingData);
    df.denormalize(validationData);
    double expResult = 1.0;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
    validationData.delete();
}

@Test
public void testValidate() {
    logger.info("validate");
    Configuration conf = Configuration.getConfiguration();
    Dataframe[] data = Datasets.heartDiseaseClusters(conf);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String dbName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = new DummyXYMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new DummyXYMinMaxNormalizer.TrainingParameters());
    df.transform(validationData);
    Kmeans instance = new Kmeans(dbName, conf);
    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);
    instance.fit(trainingData, param);
    instance.close();
    df.close();
    df = new DummyXYMinMaxNormalizer(dbName, conf);
    instance = new Kmeans(dbName, conf);
    Kmeans.ValidationMetrics vm = instance.validate(validationData);
    df.denormalize(trainingData);
    df.denormalize(validationData);
    double expResult = 1.0;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
    validationData.delete();
}


@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.multinomialClusters(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    MultinomialDPMM instance = new MultinomialDPMM(dbName, conf);
    MultinomialDPMM.TrainingParameters param = new MultinomialDPMM.TrainingParameters();
    param.setAlpha(0.01);
    param.setMaxIterations(100);
    param.setInitializationMethod(MultinomialDPMM.TrainingParameters.Initialization.ONE_CLUSTER_PER_RECORD);
    param.setAlphaWords(1);
    ClustererValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 1.0;
    double result = vm.getPurity();
    Assert.assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.multinomialClusters(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    MultinomialDPMM instance = new MultinomialDPMM(dbName, conf);
    MultinomialDPMM.TrainingParameters param = new MultinomialDPMM.TrainingParameters();
    param.setAlpha(0.01);
    param.setMaxIterations(100);
    param.setInitializationMethod(MultinomialDPMM.TrainingParameters.Initialization.ONE_CLUSTER_PER_RECORD);
    param.setAlphaWords(1);
    MultinomialDPMM.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 1.0;
    double result = vm.getPurity();
    Assert.assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}

@Test
public void testValidate() {
    logger.info("validate");
    Configuration conf = Configuration.getConfiguration();
    Dataframe[] data = Datasets.multinomialClusters(conf);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String dbName = this.getClass().getSimpleName();
    MultinomialDPMM instance = new MultinomialDPMM(dbName, conf);
    MultinomialDPMM.TrainingParameters param = new MultinomialDPMM.TrainingParameters();
    param.setAlpha(0.01);
    param.setMaxIterations(100);
    param.setInitializationMethod(MultinomialDPMM.TrainingParameters.Initialization.ONE_CLUSTER_PER_RECORD);
    param.setAlphaWords(1);
    instance.fit(trainingData, param);
    instance.close();
    instance = new MultinomialDPMM(dbName, conf);
    ClustererValidator.ValidationMetrics vm = instance.validate(validationData);
    double expResult = 1.0;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
    validationData.delete();
}

@Test
public void testValidate() {
    logger.info("validate");
    Configuration conf = Configuration.getConfiguration();
    Dataframe[] data = Datasets.multinomialClusters(conf);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String dbName = this.getClass().getSimpleName();
    MultinomialDPMM instance = new MultinomialDPMM(dbName, conf);
    MultinomialDPMM.TrainingParameters param = new MultinomialDPMM.TrainingParameters();
    param.setAlpha(0.01);
    param.setMaxIterations(100);
    param.setInitializationMethod(MultinomialDPMM.TrainingParameters.Initialization.ONE_CLUSTER_PER_RECORD);
    param.setAlphaWords(1);
    instance.fit(trainingData, param);
    instance.close();
    instance = new MultinomialDPMM(dbName, conf);
    MultinomialDPMM.ValidationMetrics vm = instance.validate(validationData);
    double expResult = 1.0;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
    validationData.delete();
}


@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    Adaboost instance = new Adaboost(dbName, conf);
    Adaboost.TrainingParameters param = new Adaboost.TrainingParameters();
    param.setMaxWeakClassifiers(5);
    param.setWeakClassifierClass(MultinomialNaiveBayes.class);
    MultinomialNaiveBayes.TrainingParameters trainingParameters = new MultinomialNaiveBayes.TrainingParameters();
    trainingParameters.setMultiProbabilityWeighted(true);
    param.setWeakClassifierTrainingParameters(trainingParameters);
    ClassifierValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6923992673992675;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    Adaboost instance = new Adaboost(dbName, conf);
    Adaboost.TrainingParameters param = new Adaboost.TrainingParameters();
    param.setMaxWeakClassifiers(5);
    param.setWeakClassifierClass(MultinomialNaiveBayes.class);
    MultinomialNaiveBayes.TrainingParameters trainingParameters = new MultinomialNaiveBayes.TrainingParameters();
    trainingParameters.setMultiProbabilityWeighted(true);
    param.setWeakClassifierTrainingParameters(trainingParameters);
    Adaboost.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6923992673992675;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}

public double getMacroF1() {
    return macroF1;
}


@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    BootstrapAggregating instance = new BootstrapAggregating(dbName, conf);
    BootstrapAggregating.TrainingParameters param = new BootstrapAggregating.TrainingParameters();
    param.setMaxWeakClassifiers(5);
    param.setWeakClassifierClass(MultinomialNaiveBayes.class);
    MultinomialNaiveBayes.TrainingParameters trainingParameters = new MultinomialNaiveBayes.TrainingParameters();
    trainingParameters.setMultiProbabilityWeighted(true);
    param.setWeakClassifierTrainingParameters(trainingParameters);
    ClassifierValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6609432234432234;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    BootstrapAggregating instance = new BootstrapAggregating(dbName, conf);
    BootstrapAggregating.TrainingParameters param = new BootstrapAggregating.TrainingParameters();
    param.setMaxWeakClassifiers(5);
    param.setWeakClassifierClass(MultinomialNaiveBayes.class);
    MultinomialNaiveBayes.TrainingParameters trainingParameters = new MultinomialNaiveBayes.TrainingParameters();
    trainingParameters.setMultiProbabilityWeighted(true);
    param.setWeakClassifierTrainingParameters(trainingParameters);
    BootstrapAggregating.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6609432234432234;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}


@Test
public void testValidate() {
    logger.info("validate");
    Configuration conf = Configuration.getConfiguration();
    Dataframe[] data = Datasets.recommenderSystemFood(conf);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String dbName = this.getClass().getSimpleName();
    CollaborativeFiltering instance = new CollaborativeFiltering(dbName, conf);
    CollaborativeFiltering.TrainingParameters param = new CollaborativeFiltering.TrainingParameters();
    param.setSimilarityMethod(CollaborativeFiltering.TrainingParameters.SimilarityMeasure.PEARSONS_CORRELATION);
    instance.fit(trainingData, param);
    instance.close();
    instance = new CollaborativeFiltering(dbName, conf);
    RMSEValidator.ValidationMetrics vm = instance.validate(validationData);
    Map<Object, Double> expResult = new HashMap<>();
    expResult.put("pitta", 4.686394033077408);
    expResult.put("burger", 4.68408210680137);
    expResult.put("pizza", 4.6194430718558745);
    expResult.put("chocolate", 4.580630241051733);
    expResult.put("potato", 4.291658734729706);
    expResult.put("beer", 4.264285969929414);
    expResult.put("sparklewatter", 2.8034325749458997);
    expResult.put("salad", 1.496493323119103);
    expResult.put("risecookie", 1.372309723394662);
    expResult.put("tea", 1.3577402217087802);
    expResult.put("rise", 1.2243050068650592);
    AssociativeArray result = validationData.iterator().next().getYPredictedProbabilities();
    for (Map.Entry<Object, Object> entry : result.entrySet()) {
        assertEquals(expResult.get(entry.getKey()), TypeInference.toDouble(entry.getValue()), Constants.DOUBLE_ACCURACY_HIGH);
    }
    assertEquals(vm.getRMSE(), 0.7184568473420477, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
    validationData.delete();
}

@Test
public void testValidate() {
    logger.info("validate");
    Configuration conf = Configuration.getConfiguration();
    Dataframe[] data = Datasets.recommenderSystemFood(conf);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String dbName = this.getClass().getSimpleName();
    CollaborativeFiltering instance = new CollaborativeFiltering(dbName, conf);
    CollaborativeFiltering.TrainingParameters param = new CollaborativeFiltering.TrainingParameters();
    param.setSimilarityMethod(CollaborativeFiltering.TrainingParameters.SimilarityMeasure.PEARSONS_CORRELATION);
    instance.fit(trainingData, param);
    instance.close();
    instance = new CollaborativeFiltering(dbName, conf);
    CollaborativeFiltering.ValidationMetrics vm = instance.validate(validationData);
    Map<Object, Double> expResult = new HashMap<>();
    expResult.put("pitta", 4.686394033077408);
    expResult.put("burger", 4.68408210680137);
    expResult.put("pizza", 4.6194430718558745);
    expResult.put("chocolate", 4.580630241051733);
    expResult.put("potato", 4.291658734729706);
    expResult.put("beer", 4.264285969929414);
    expResult.put("sparklewatter", 2.8034325749458997);
    expResult.put("salad", 1.496493323119103);
    expResult.put("risecookie", 1.372309723394662);
    expResult.put("tea", 1.3577402217087802);
    expResult.put("rise", 1.2243050068650592);
    AssociativeArray result = validationData.iterator().next().getYPredictedProbabilities();
    for (Map.Entry<Object, Object> entry : result.entrySet()) {
        assertEquals(expResult.get(entry.getKey()), TypeInference.toDouble(entry.getValue()), Constants.DOUBLE_ACCURACY_HIGH);
    }
    assertEquals(vm.getRMSE(), 0.7184568473420477, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
    validationData.delete();
}


@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.regressionMixed(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = new DummyXYMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new DummyXYMinMaxNormalizer.TrainingParameters());
    MatrixLinearRegression instance = new MatrixLinearRegression(dbName, conf);
    MatrixLinearRegression.TrainingParameters param = new MatrixLinearRegression.TrainingParameters();
    LinearRegressionValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    df.denormalize(trainingData);
    double expResult = 1;
    double result = vm.getRSquare();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.regressionMixed(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = new DummyXYMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new DummyXYMinMaxNormalizer.TrainingParameters());
    MatrixLinearRegression instance = new MatrixLinearRegression(dbName, conf);
    MatrixLinearRegression.TrainingParameters param = new MatrixLinearRegression.TrainingParameters();
    MatrixLinearRegression.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    df.denormalize(trainingData);
    double expResult = 1;
    double result = vm.getRSquare();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
}


@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.housingNumerical(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = new DummyXYMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new DummyXYMinMaxNormalizer.TrainingParameters());
    PCA featureSelector = new PCA(dbName, conf);
    PCA.TrainingParameters featureSelectorParameters = new PCA.TrainingParameters();
    featureSelectorParameters.setMaxDimensions(trainingData.xColumnSize() - 1);
    featureSelectorParameters.setWhitened(false);
    featureSelectorParameters.setVariancePercentageThreshold(0.99999995);
    featureSelector.fit_transform(trainingData, featureSelectorParameters);
    featureSelector.delete();
    NLMS instance = new NLMS(dbName, conf);
    NLMS.TrainingParameters param = new NLMS.TrainingParameters();
    param.setTotalIterations(500);
    param.setL1(0.001);
    param.setL2(0.001);
    LinearRegressionValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    df.denormalize(trainingData);
    double expResult = 0.7748106446239166;
    double result = vm.getRSquare();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.housingNumerical(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = new DummyXYMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new DummyXYMinMaxNormalizer.TrainingParameters());
    PCA featureSelector = new PCA(dbName, conf);
    PCA.TrainingParameters featureSelectorParameters = new PCA.TrainingParameters();
    featureSelectorParameters.setMaxDimensions(trainingData.xColumnSize() - 1);
    featureSelectorParameters.setWhitened(false);
    featureSelectorParameters.setVariancePercentageThreshold(0.99999995);
    featureSelector.fit_transform(trainingData, featureSelectorParameters);
    featureSelector.delete();
    NLMS instance = new NLMS(dbName, conf);
    NLMS.TrainingParameters param = new NLMS.TrainingParameters();
    param.setTotalIterations(500);
    param.setL1(0.001);
    param.setL2(0.001);
    NLMS.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    df.denormalize(trainingData);
    double expResult = 0.7748106446239166;
    double result = vm.getRSquare();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
}


@Test
public void testValidate() {
    logger.info("validate");
    Configuration conf = Configuration.getConfiguration();
    String dbName = this.getClass().getSimpleName();
    Map<Object, URI> dataset = new HashMap<>();
    try {
        dataset.put("negative", this.getClass().getClassLoader().getResource("datasets/sentimentAnalysis.neg.txt").toURI());
        dataset.put("positive", this.getClass().getClassLoader().getResource("datasets/sentimentAnalysis.pos.txt").toURI());
    } catch (UncheckedIOException | URISyntaxException ex) {
        logger.warn("Unable to download datasets, skipping test.");
        throw new RuntimeException(ex);
    }
    UniqueWordSequenceExtractor wsExtractor = new UniqueWordSequenceExtractor(new UniqueWordSequenceExtractor.Parameters());
    Dataframe trainingData = Dataframe.Builder.parseTextFiles(dataset, wsExtractor, conf);
    LatentDirichletAllocation lda = new LatentDirichletAllocation(dbName, conf);
    LatentDirichletAllocation.TrainingParameters trainingParameters = new LatentDirichletAllocation.TrainingParameters();
    trainingParameters.setMaxIterations(15);
    trainingParameters.setAlpha(0.01);
    trainingParameters.setBeta(0.01);
    trainingParameters.setK(25);
    lda.fit(trainingData, trainingParameters);
    lda.predict(trainingData);
    Dataframe reducedTrainingData = new Dataframe(conf);
    for (Record r : trainingData) {
        reducedTrainingData.add(new Record(r.getYPredictedProbabilities(), r.getY()));
    }
    SoftMaxRegression smr = new SoftMaxRegression(dbName, conf);
    SoftMaxRegression.TrainingParameters tp = new SoftMaxRegression.TrainingParameters();
    tp.setLearningRate(1.0);
    tp.setTotalIterations(50);
    ClassifierValidator.ValidationMetrics vm = smr.kFoldCrossValidation(reducedTrainingData, tp, 1);
    double expResult = 0.6843125117743629;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    smr.delete();
    lda.delete();
    reducedTrainingData.delete();
    trainingData.delete();
}

@Test
public void testValidate() {
    logger.info("validate");
    Configuration conf = Configuration.getConfiguration();
    String dbName = this.getClass().getSimpleName();
    Map<Object, URI> dataset = new HashMap<>();
    try {
        dataset.put("negative", this.getClass().getClassLoader().getResource("datasets/sentimentAnalysis.neg.txt").toURI());
        dataset.put("positive", this.getClass().getClassLoader().getResource("datasets/sentimentAnalysis.pos.txt").toURI());
    } catch (UncheckedIOException | URISyntaxException ex) {
        logger.warn("Unable to download datasets, skipping test.");
        throw new RuntimeException(ex);
    }
    UniqueWordSequenceExtractor wsExtractor = new UniqueWordSequenceExtractor(new UniqueWordSequenceExtractor.Parameters());
    Dataframe trainingData = Dataframe.Builder.parseTextFiles(dataset, wsExtractor, conf);
    LatentDirichletAllocation lda = new LatentDirichletAllocation(dbName, conf);
    LatentDirichletAllocation.TrainingParameters trainingParameters = new LatentDirichletAllocation.TrainingParameters();
    trainingParameters.setMaxIterations(15);
    trainingParameters.setAlpha(0.01);
    trainingParameters.setBeta(0.01);
    trainingParameters.setK(25);
    lda.fit(trainingData, trainingParameters);
    lda.validate(trainingData);
    Dataframe reducedTrainingData = new Dataframe(conf);
    for (Record r : trainingData) {
        reducedTrainingData.add(new Record(r.getYPredictedProbabilities(), r.getY()));
    }
    SoftMaxRegression smr = new SoftMaxRegression(dbName, conf);
    SoftMaxRegression.TrainingParameters tp = new SoftMaxRegression.TrainingParameters();
    tp.setLearningRate(1.0);
    tp.setTotalIterations(50);
    SoftMaxRegression.ValidationMetrics vm = smr.kFoldCrossValidation(reducedTrainingData, tp, 1);
    double expResult = 0.6843125117743629;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    smr.delete();
    lda.delete();
    reducedTrainingData.delete();
    trainingData.delete();
}


@Test
public void testTrainAndValidate() {
    logger.info("testTrainAndValidate");
    Configuration conf = Configuration.getConfiguration();
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String dbName = this.getClass().getSimpleName();
    Modeler instance = new Modeler(dbName, conf);
    Modeler.TrainingParameters trainingParameters = new Modeler.TrainingParameters();
    trainingParameters.setModelerClass(MultinomialNaiveBayes.class);
    MultinomialNaiveBayes.TrainingParameters modelTrainingParameters = new MultinomialNaiveBayes.TrainingParameters();
    modelTrainingParameters.setMultiProbabilityWeighted(true);
    trainingParameters.setModelerTrainingParameters(modelTrainingParameters);
    trainingParameters.setDataTransformerClass(DummyXMinMaxNormalizer.class);
    DummyXMinMaxNormalizer.TrainingParameters dtParams = new DummyXMinMaxNormalizer.TrainingParameters();
    trainingParameters.setDataTransformerTrainingParameters(dtParams);
    trainingParameters.setFeatureSelectorClass(null);
    trainingParameters.setFeatureSelectorTrainingParameters(null);
    instance.fit(trainingData, trainingParameters);
    MultinomialNaiveBayes.ValidationMetrics vm = (MultinomialNaiveBayes.ValidationMetrics) instance.validate(trainingData);
    instance.setValidationMetrics(vm);
    double expResult2 = 0.8;
    Assert.assertEquals(expResult2, vm.getMacroF1(), Constants.DOUBLE_ACCURACY_HIGH);
    instance.close();
    logger.info("validate");
    instance = new Modeler(dbName, conf);
    instance.validate(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);
    instance.delete();
    trainingData.delete();
    validationData.delete();
}

@Test
public void testTrainAndValidate() {
    logger.info("testTrainAndValidate");
    Configuration conf = Configuration.getConfiguration();
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String dbName = this.getClass().getSimpleName();
    Modeler instance = new Modeler(dbName, conf);
    Modeler.TrainingParameters trainingParameters = new Modeler.TrainingParameters();
    trainingParameters.setModelerClass(MultinomialNaiveBayes.class);
    MultinomialNaiveBayes.TrainingParameters modelTrainingParameters = new MultinomialNaiveBayes.TrainingParameters();
    modelTrainingParameters.setMultiProbabilityWeighted(true);
    trainingParameters.setModelerTrainingParameters(modelTrainingParameters);
    trainingParameters.setDataTransformerClass(DummyXMinMaxNormalizer.class);
    DummyXMinMaxNormalizer.TrainingParameters dtParams = new DummyXMinMaxNormalizer.TrainingParameters();
    trainingParameters.setDataTransformerTrainingParameters(dtParams);
    trainingParameters.setFeatureSelectorClass(null);
    trainingParameters.setFeatureSelectorTrainingParameters(null);
    instance.fit(trainingData, trainingParameters);
    instance.close();
    logger.info("validate");
    instance = new Modeler(dbName, conf);
    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);
    instance.delete();
    trainingData.delete();
    validationData.delete();
}

public ValidationMetrics validate(Dataframe testData) {
    logger.info("validate()");
    return evaluateData(testData, true);
}


@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    BernoulliNaiveBayes instance = new BernoulliNaiveBayes(dbName, conf);
    BernoulliNaiveBayes.TrainingParameters param = new BernoulliNaiveBayes.TrainingParameters();
    BernoulliNaiveBayes.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6631318681318682;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    BernoulliNaiveBayes instance = new BernoulliNaiveBayes(dbName, conf);
    BernoulliNaiveBayes.TrainingParameters param = new BernoulliNaiveBayes.TrainingParameters();
    ClassifierValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6631318681318682;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}

@Override
public void delete() {
    kb().delete();
}

@Override
public void delete() {
    knowledgeBase.delete();
}


@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    BinarizedNaiveBayes instance = new BinarizedNaiveBayes(dbName, conf);
    BinarizedNaiveBayes.TrainingParameters param = new BinarizedNaiveBayes.TrainingParameters();
    BinarizedNaiveBayes.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6631318681318682;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    BinarizedNaiveBayes instance = new BinarizedNaiveBayes(dbName, conf);
    BinarizedNaiveBayes.TrainingParameters param = new BinarizedNaiveBayes.TrainingParameters();
    ClassifierValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6631318681318682;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}


@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    MaximumEntropy instance = new MaximumEntropy(dbName, conf);
    MaximumEntropy.TrainingParameters param = new MaximumEntropy.TrainingParameters();
    param.setTotalIterations(10);
    MaximumEntropy.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6051098901098901;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    MaximumEntropy instance = new MaximumEntropy(dbName, conf);
    MaximumEntropy.TrainingParameters param = new MaximumEntropy.TrainingParameters();
    param.setTotalIterations(10);
    ClassifierValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6051098901098901;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}


@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    MultinomialNaiveBayes instance = new MultinomialNaiveBayes(dbName, conf);
    MultinomialNaiveBayes.TrainingParameters param = new MultinomialNaiveBayes.TrainingParameters();
    param.setMultiProbabilityWeighted(true);
    MultinomialNaiveBayes.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6631318681318682;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    MultinomialNaiveBayes instance = new MultinomialNaiveBayes(dbName, conf);
    MultinomialNaiveBayes.TrainingParameters param = new MultinomialNaiveBayes.TrainingParameters();
    param.setMultiProbabilityWeighted(true);
    ClassifierValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6631318681318682;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}


@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.winesOrdinal(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    DummyXMinMaxNormalizer df = new DummyXMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new DummyXMinMaxNormalizer.TrainingParameters());
    OrdinalRegression instance = new OrdinalRegression(dbName, conf);
    OrdinalRegression.TrainingParameters param = new OrdinalRegression.TrainingParameters();
    param.setTotalIterations(100);
    param.setL2(0.001);
    OrdinalRegression.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    df.denormalize(trainingData);
    double expResult = 0.9823403146614675;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.winesOrdinal(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    DummyXMinMaxNormalizer df = new DummyXMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new DummyXMinMaxNormalizer.TrainingParameters());
    OrdinalRegression instance = new OrdinalRegression(dbName, conf);
    OrdinalRegression.TrainingParameters param = new OrdinalRegression.TrainingParameters();
    param.setTotalIterations(100);
    param.setL2(0.001);
    ClassifierValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    df.denormalize(trainingData);
    double expResult = 0.9823403146614675;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
}

public void denormalize(Dataframe data) {
    logger.info("denormalize()");
    kb().load();
    _denormalize(data);
}

public void denormalize(Dataframe data) {
    logger.info("denormalize()");
    knowledgeBase.load();
    _denormalize(data);
}


@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    XMinMaxNormalizer df = new XMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new XMinMaxNormalizer.TrainingParameters());
    SoftMaxRegression instance = new SoftMaxRegression(dbName, conf);
    SoftMaxRegression.TrainingParameters param = new SoftMaxRegression.TrainingParameters();
    param.setTotalIterations(30);
    param.setL1(0.0001);
    param.setL2(0.0001);
    SoftMaxRegression.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    df.denormalize(trainingData);
    double expResult = 0.7557492507492508;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    XMinMaxNormalizer df = new XMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new XMinMaxNormalizer.TrainingParameters());
    SoftMaxRegression instance = new SoftMaxRegression(dbName, conf);
    SoftMaxRegression.TrainingParameters param = new SoftMaxRegression.TrainingParameters();
    param.setTotalIterations(30);
    param.setL1(0.0001);
    param.setL2(0.0001);
    ClassifierValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    df.denormalize(trainingData);
    double expResult = 0.7557492507492508;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
}


@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    SupportVectorMachine instance = new SupportVectorMachine(dbName, conf);
    SupportVectorMachine.TrainingParameters param = new SupportVectorMachine.TrainingParameters();
    param.getSvmParameter().kernel_type = svm_parameter.LINEAR;
    SupportVectorMachine.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6473992673992675;
    double result = vm.getMacroF1();
    Assert.assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    SupportVectorMachine instance = new SupportVectorMachine(dbName, conf);
    SupportVectorMachine.TrainingParameters param = new SupportVectorMachine.TrainingParameters();
    param.getSvmParameter().kernel_type = svm_parameter.LINEAR;
    ClassifierValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6473992673992675;
    double result = vm.getMacroF1();
    Assert.assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}


@Test
public void testValidate() {
    logger.info("validate");
    Configuration conf = Configuration.getConfiguration();
    Dataframe[] data = Datasets.gaussianClusters(conf);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String dbName = this.getClass().getSimpleName();
    GaussianDPMM instance = new GaussianDPMM(dbName, conf);
    GaussianDPMM.TrainingParameters param = new GaussianDPMM.TrainingParameters();
    param.setAlpha(0.01);
    param.setMaxIterations(100);
    param.setInitializationMethod(GaussianDPMM.TrainingParameters.Initialization.ONE_CLUSTER_PER_RECORD);
    param.setKappa0(0);
    param.setNu0(1);
    param.setMu0(new double[] { 0.0, 0.0 });
    param.setPsi0(new double[][] { { 1.0, 0.0 }, { 0.0, 1.0 } });
    instance.fit(trainingData, param);
    instance.close();
    instance = new GaussianDPMM(dbName, conf);
    GaussianDPMM.ValidationMetrics vm = instance.validate(validationData);
    double expResult = 1.0;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
    validationData.delete();
}

@Test
public void testValidate() {
    logger.info("validate");
    Configuration conf = Configuration.getConfiguration();
    Dataframe[] data = Datasets.gaussianClusters(conf);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String dbName = this.getClass().getSimpleName();
    GaussianDPMM instance = new GaussianDPMM(dbName, conf);
    GaussianDPMM.TrainingParameters param = new GaussianDPMM.TrainingParameters();
    param.setAlpha(0.01);
    param.setMaxIterations(100);
    param.setInitializationMethod(GaussianDPMM.TrainingParameters.Initialization.ONE_CLUSTER_PER_RECORD);
    param.setKappa0(0);
    param.setNu0(1);
    param.setMu0(new double[] { 0.0, 0.0 });
    param.setPsi0(new double[][] { { 1.0, 0.0 }, { 0.0, 1.0 } });
    instance.fit(trainingData, param);
    instance.close();
    instance = new GaussianDPMM(dbName, conf);
    ClustererValidator.ValidationMetrics vm = instance.validate(validationData);
    double expResult = 1.0;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
    validationData.delete();
}

public VM validate(Dataframe testingData) {
    logger.info("validate()");
    kb().load();
    VM validationMetrics = validateModel(testingData);
    return validationMetrics;
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.gaussianClusters(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    GaussianDPMM instance = new GaussianDPMM(dbName, conf);
    GaussianDPMM.TrainingParameters param = new GaussianDPMM.TrainingParameters();
    param.setAlpha(0.01);
    param.setMaxIterations(100);
    param.setInitializationMethod(GaussianDPMM.TrainingParameters.Initialization.ONE_CLUSTER_PER_RECORD);
    param.setKappa0(0);
    param.setNu0(1);
    param.setMu0(new double[] { 0.0, 0.0 });
    param.setPsi0(new double[][] { { 1.0, 0.0 }, { 0.0, 1.0 } });
    GaussianDPMM.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 1.0;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.gaussianClusters(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    GaussianDPMM instance = new GaussianDPMM(dbName, conf);
    GaussianDPMM.TrainingParameters param = new GaussianDPMM.TrainingParameters();
    param.setAlpha(0.01);
    param.setMaxIterations(100);
    param.setInitializationMethod(GaussianDPMM.TrainingParameters.Initialization.ONE_CLUSTER_PER_RECORD);
    param.setKappa0(0);
    param.setNu0(1);
    param.setMu0(new double[] { 0.0, 0.0 });
    param.setPsi0(new double[][] { { 1.0, 0.0 }, { 0.0, 1.0 } });
    ClustererValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 1.0;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}


@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.heartDiseaseClusters(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = new DummyXYMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new DummyXYMinMaxNormalizer.TrainingParameters());
    HierarchicalAgglomerative instance = new HierarchicalAgglomerative(dbName, conf);
    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.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    df.denormalize(trainingData);
    double expResult = 0.7666666666666667;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.heartDiseaseClusters(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = new DummyXYMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new DummyXYMinMaxNormalizer.TrainingParameters());
    HierarchicalAgglomerative instance = new HierarchicalAgglomerative(dbName, conf);
    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);
    ClustererValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    df.denormalize(trainingData);
    double expResult = 0.7666666666666667;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
}

@Test
public void testValidate() {
    logger.info("validate");
    Configuration conf = Configuration.getConfiguration();
    Dataframe[] data = Datasets.heartDiseaseClusters(conf);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String dbName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = new DummyXYMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new DummyXYMinMaxNormalizer.TrainingParameters());
    df.transform(validationData);
    HierarchicalAgglomerative instance = new HierarchicalAgglomerative(dbName, conf);
    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);
    instance.fit(trainingData, param);
    instance.close();
    df.close();
    df = new DummyXYMinMaxNormalizer(dbName, conf);
    instance = new HierarchicalAgglomerative(dbName, conf);
    HierarchicalAgglomerative.ValidationMetrics vm = instance.validate(validationData);
    df.denormalize(trainingData);
    df.denormalize(validationData);
    double expResult = 1.0;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
    validationData.delete();
}

@Test
public void testValidate() {
    logger.info("validate");
    Configuration conf = Configuration.getConfiguration();
    Dataframe[] data = Datasets.heartDiseaseClusters(conf);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String dbName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = new DummyXYMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new DummyXYMinMaxNormalizer.TrainingParameters());
    df.transform(validationData);
    HierarchicalAgglomerative instance = new HierarchicalAgglomerative(dbName, conf);
    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);
    instance.fit(trainingData, param);
    instance.close();
    df.close();
    df = new DummyXYMinMaxNormalizer(dbName, conf);
    instance = new HierarchicalAgglomerative(dbName, conf);
    ClustererValidator.ValidationMetrics vm = instance.validate(validationData);
    df.denormalize(trainingData);
    df.denormalize(validationData);
    double expResult = 1.0;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
    validationData.delete();
}


@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.heartDiseaseClusters(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = new DummyXYMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new DummyXYMinMaxNormalizer.TrainingParameters());
    Kmeans instance = new Kmeans(dbName, conf);
    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.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    df.denormalize(trainingData);
    double expResult = 0.7888888888888889;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.heartDiseaseClusters(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = new DummyXYMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new DummyXYMinMaxNormalizer.TrainingParameters());
    Kmeans instance = new Kmeans(dbName, conf);
    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);
    ClustererValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    df.denormalize(trainingData);
    double expResult = 0.7888888888888889;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
}

@Test
public void testValidate() {
    logger.info("validate");
    Configuration conf = Configuration.getConfiguration();
    Dataframe[] data = Datasets.heartDiseaseClusters(conf);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String dbName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = new DummyXYMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new DummyXYMinMaxNormalizer.TrainingParameters());
    df.transform(validationData);
    Kmeans instance = new Kmeans(dbName, conf);
    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);
    instance.fit(trainingData, param);
    instance.close();
    df.close();
    df = new DummyXYMinMaxNormalizer(dbName, conf);
    instance = new Kmeans(dbName, conf);
    Kmeans.ValidationMetrics vm = instance.validate(validationData);
    df.denormalize(trainingData);
    df.denormalize(validationData);
    double expResult = 1.0;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
    validationData.delete();
}

@Test
public void testValidate() {
    logger.info("validate");
    Configuration conf = Configuration.getConfiguration();
    Dataframe[] data = Datasets.heartDiseaseClusters(conf);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String dbName = this.getClass().getSimpleName();
    DummyXYMinMaxNormalizer df = new DummyXYMinMaxNormalizer(dbName, conf);
    df.fit_transform(trainingData, new DummyXYMinMaxNormalizer.TrainingParameters());
    df.transform(validationData);
    Kmeans instance = new Kmeans(dbName, conf);
    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);
    instance.fit(trainingData, param);
    instance.close();
    df.close();
    df = new DummyXYMinMaxNormalizer(dbName, conf);
    instance = new Kmeans(dbName, conf);
    ClustererValidator.ValidationMetrics vm = instance.validate(validationData);
    df.denormalize(trainingData);
    df.denormalize(validationData);
    double expResult = 1.0;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    df.delete();
    instance.delete();
    trainingData.delete();
    validationData.delete();
}


@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.multinomialClusters(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    MultinomialDPMM instance = new MultinomialDPMM(dbName, conf);
    MultinomialDPMM.TrainingParameters param = new MultinomialDPMM.TrainingParameters();
    param.setAlpha(0.01);
    param.setMaxIterations(100);
    param.setInitializationMethod(MultinomialDPMM.TrainingParameters.Initialization.ONE_CLUSTER_PER_RECORD);
    param.setAlphaWords(1);
    MultinomialDPMM.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 1.0;
    double result = vm.getPurity();
    Assert.assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.multinomialClusters(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    MultinomialDPMM instance = new MultinomialDPMM(dbName, conf);
    MultinomialDPMM.TrainingParameters param = new MultinomialDPMM.TrainingParameters();
    param.setAlpha(0.01);
    param.setMaxIterations(100);
    param.setInitializationMethod(MultinomialDPMM.TrainingParameters.Initialization.ONE_CLUSTER_PER_RECORD);
    param.setAlphaWords(1);
    ClustererValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 1.0;
    double result = vm.getPurity();
    Assert.assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}

@Test
public void testValidate() {
    logger.info("validate");
    Configuration conf = Configuration.getConfiguration();
    Dataframe[] data = Datasets.multinomialClusters(conf);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String dbName = this.getClass().getSimpleName();
    MultinomialDPMM instance = new MultinomialDPMM(dbName, conf);
    MultinomialDPMM.TrainingParameters param = new MultinomialDPMM.TrainingParameters();
    param.setAlpha(0.01);
    param.setMaxIterations(100);
    param.setInitializationMethod(MultinomialDPMM.TrainingParameters.Initialization.ONE_CLUSTER_PER_RECORD);
    param.setAlphaWords(1);
    instance.fit(trainingData, param);
    instance.close();
    instance = new MultinomialDPMM(dbName, conf);
    instance.validate(validationData);
    MultinomialDPMM.ValidationMetrics vm = instance.validate(validationData);
    double expResult = 1.0;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
    validationData.delete();
}

@Test
public void testValidate() {
    logger.info("validate");
    Configuration conf = Configuration.getConfiguration();
    Dataframe[] data = Datasets.multinomialClusters(conf);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String dbName = this.getClass().getSimpleName();
    MultinomialDPMM instance = new MultinomialDPMM(dbName, conf);
    MultinomialDPMM.TrainingParameters param = new MultinomialDPMM.TrainingParameters();
    param.setAlpha(0.01);
    param.setMaxIterations(100);
    param.setInitializationMethod(MultinomialDPMM.TrainingParameters.Initialization.ONE_CLUSTER_PER_RECORD);
    param.setAlphaWords(1);
    instance.fit(trainingData, param);
    instance.close();
    instance = new MultinomialDPMM(dbName, conf);
    ClustererValidator.ValidationMetrics vm = instance.validate(validationData);
    double expResult = 1.0;
    double result = vm.getPurity();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
    validationData.delete();
}


@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    Adaboost instance = new Adaboost(dbName, conf);
    Adaboost.TrainingParameters param = new Adaboost.TrainingParameters();
    param.setMaxWeakClassifiers(5);
    param.setWeakClassifierClass(MultinomialNaiveBayes.class);
    MultinomialNaiveBayes.TrainingParameters trainingParameters = new MultinomialNaiveBayes.TrainingParameters();
    trainingParameters.setMultiProbabilityWeighted(true);
    param.setWeakClassifierTrainingParameters(trainingParameters);
    Adaboost.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6923992673992675;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    Adaboost instance = new Adaboost(dbName, conf);
    Adaboost.TrainingParameters param = new Adaboost.TrainingParameters();
    param.setMaxWeakClassifiers(5);
    param.setWeakClassifierClass(MultinomialNaiveBayes.class);
    MultinomialNaiveBayes.TrainingParameters trainingParameters = new MultinomialNaiveBayes.TrainingParameters();
    trainingParameters.setMultiProbabilityWeighted(true);
    param.setWeakClassifierTrainingParameters(trainingParameters);
    ClassifierValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6923992673992675;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}

public double getMacroF1() {
    return macroF1;
}


@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    BootstrapAggregating instance = new BootstrapAggregating(dbName, conf);
    BootstrapAggregating.TrainingParameters param = new BootstrapAggregating.TrainingParameters();
    param.setMaxWeakClassifiers(5);
    param.setWeakClassifierClass(MultinomialNaiveBayes.class);
    MultinomialNaiveBayes.TrainingParameters trainingParameters = new MultinomialNaiveBayes.TrainingParameters();
    trainingParameters.setMultiProbabilityWeighted(true);
    param.setWeakClassifierTrainingParameters(trainingParameters);
    BootstrapAggregating.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6609432234432234;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}

@Test
public void testKFoldCrossValidation() {
    logger.info("kFoldCrossValidation");
    Configuration conf = Configuration.getConfiguration();
    int k = 5;
    Dataframe[] data = Datasets.carsNumeric(conf);
    Dataframe trainingData = data[0];
    data[1].delete();
    String dbName = this.getClass().getSimpleName();
    BootstrapAggregating instance = new BootstrapAggregating(dbName, conf);
    BootstrapAggregating.TrainingParameters param = new BootstrapAggregating.TrainingParameters();
    param.setMaxWeakClassifiers(5);
    param.setWeakClassifierClass(MultinomialNaiveBayes.class);
    MultinomialNaiveBayes.TrainingParameters trainingParameters = new MultinomialNaiveBayes.TrainingParameters();
    trainingParameters.setMultiProbabilityWeighted(true);
    param.setWeakClassifierTrainingParameters(trainingParameters);
    ClassifierValidator.ValidationMetrics vm = instance.kFoldCrossValidation(trainingData, param, k);
    double expResult = 0.6609432234432234;
    double result = vm.getMacroF1();
    assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
}


@Test
public void testValidate() {
    logger.info("validate");
    Configuration conf = Configuration.getConfiguration();
    Dataframe[] data = Datasets.recommenderSystemFood(conf);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String dbName = this.getClass().getSimpleName();
    CollaborativeFiltering instance = new CollaborativeFiltering(dbName, conf);
    CollaborativeFiltering.TrainingParameters param = new CollaborativeFiltering.TrainingParameters();
    param.setSimilarityMethod(CollaborativeFiltering.TrainingParameters.SimilarityMeasure.PEARSONS_CORRELATION);
    instance.fit(trainingData, param);
    instance.close();
    instance = new CollaborativeFiltering(dbName, conf);
    CollaborativeFiltering.ValidationMetrics vm = instance.validate(validationData);
    Map<Object, Double> expResult = new HashMap<>();
    expResult.put("pitta", 4.686394033077408);
    expResult.put("burger", 4.68408210680137);
    expResult.put("pizza", 4.6194430718558745);
    expResult.put("chocolate", 4.580630241051733);
    expResult.put("potato", 4.291658734729706);
    expResult.put("beer", 4.264285969929414);
    expResult.put("sparklewatter", 2.8034325749458997);
    expResult.put("salad", 1.496493323119103);
    expResult.put("risecookie", 1.372309723394662);
    expResult.put("tea", 1.3577402217087802);
    expResult.put("rise", 1.2243050068650592);
    AssociativeArray result = validationData.iterator().next().getYPredictedProbabilities();
    for (Map.Entry<Object, Object> entry : result.entrySet()) {
        assertEquals(expResult.get(entry.getKey()), TypeInference.toDouble(entry.getValue()), Constants.DOUBLE_ACCURACY_HIGH);
    }
    assertEquals(vm.getRMSE(), 0.7184568473420477, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
    validationData.delete();
}

@Test
public void testValidate() {
    logger.info("validate");
    Configuration conf = Configuration.getConfiguration();
    Dataframe[] data = Datasets.recommenderSystemFood(conf);
    Dataframe trainingData = data[0];
    Dataframe validationData = data[1];
    String dbName = this.getClass().getSimpleName();
    CollaborativeFiltering instance = new CollaborativeFiltering(dbName, conf);
    CollaborativeFiltering.TrainingParameters param = new CollaborativeFiltering.TrainingParameters();
    param.setSimilarityMethod(CollaborativeFiltering.TrainingParameters.SimilarityMeasure.PEARSONS_CORRELATION);
    instance.fit(trainingData, param);
    instance.close();
    instance = new CollaborativeFiltering(dbName, conf);
    RMSEValidator.ValidationMetrics vm = instance.validate(validationData);
    Map<Object, Double> expResult = new HashMap<>();
    expResult.put("pitta", 4.686394033077408);
    expResult.put("burger", 4.68408210680137);
    expResult.put("pizza", 4.6194430718558745);
    expResult.put("chocolate", 4.580630241051733);
    expResult.put("potato", 4.291658734729706);
    expResult.put("beer", 4.264285969929414);
    expResult.put("sparklewatter", 2.8034325749458997);
    expResult.put("salad", 1.496493323119103);
    expResult.put("risecookie", 1.372309723394662);
    expResult.put("tea", 1.3577402217087802);
    expResult.put("rise", 1.2243050068650592);
    AssociativeArray result = validationData.iterator().next().getYPredictedProbabilities();
    for (Map.Entry<Object, Object> entry : result.entrySet()) {
        assertEquals(expResult.get(entry.getKey()), TypeInference.toDouble(entry.getValue()), Constants.DOUBLE_ACCURACY_HIGH);
    }
    assertEquals(vm.getRMSE(), 0.7184568473420477, Constants.DOUBLE_ACCURACY_HIGH);
    instance.delete();
    trainingData.delete();
    validationData.delete();
}