use of org.kie.pmml.models.mining.model.KiePMMLMiningModel in project drools by kiegroup.
the class PMMLMiningModelEvaluatorTest method getPMML4ResultOK.
@Test
public void getPMML4ResultOK() {
String name = "NAME";
String targetField = "TARGET";
String prediction = "FIRST_VALUE";
KiePMMLSegmentation kiePMMLSegmentation = KiePMMLSegmentation.builder("SEGM_1", Collections.emptyList(), SELECT_FIRST).build();
KiePMMLMiningModel kiePMMLMiningModel = KiePMMLMiningModel.builder(name, Collections.emptyList(), MINING_FUNCTION.ASSOCIATION_RULES).withTargetField(targetField).withSegmentation(kiePMMLSegmentation).build();
final LinkedHashMap<String, PMMLMiningModelEvaluator.KiePMMLNameValueProbabilityMapTuple> inputData = new LinkedHashMap<>();
inputData.put("FIRST_KEY", new PMMLMiningModelEvaluator.KiePMMLNameValueProbabilityMapTuple(new KiePMMLNameValue("FIRST_NAME", prediction), new ArrayList<>()));
inputData.put("SECOND_KEY", new PMMLMiningModelEvaluator.KiePMMLNameValueProbabilityMapTuple(new KiePMMLNameValue("SECOND_NAME", "SECOND_VALUE"), new ArrayList<>()));
PMML4Result retrieved = evaluator.getPMML4Result(kiePMMLMiningModel, inputData, new PMMLContextTest());
assertNotNull(retrieved);
assertEquals(OK.getName(), retrieved.getResultCode());
assertEquals(targetField, retrieved.getResultObjectName());
final Map<String, Object> resultVariables = retrieved.getResultVariables();
assertTrue(resultVariables.containsKey(targetField));
assertEquals(prediction, resultVariables.get(targetField));
}
use of org.kie.pmml.models.mining.model.KiePMMLMiningModel in project drools by kiegroup.
the class KiePMMLMiningModelFactory method getKiePMMLMiningModel.
public static KiePMMLMiningModel getKiePMMLMiningModel(final MiningModelCompilationDTO compilationDTO) {
logger.debug("getKiePMMLMiningModel {}", compilationDTO.getModel());
final List<KiePMMLModel> nestedModels = new ArrayList<>();
Map<String, String> sourcesMap = getKiePMMLMiningModelSourcesMapCompiled(compilationDTO, nestedModels);
try {
Class<?> kiePMMLMiningModel = compilationDTO.compileAndLoadClass(sourcesMap);
return (KiePMMLMiningModel) kiePMMLMiningModel.newInstance();
} catch (Exception e) {
throw new KiePMMLException(e);
}
}
use of org.kie.pmml.models.mining.model.KiePMMLMiningModel in project drools by kiegroup.
the class KiePMMLMiningModelFactoryTest method getKiePMMLMiningModel.
@Test
public void getKiePMMLMiningModel() {
final CommonCompilationDTO<MiningModel> source = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, MINING_MODEL, new HasKnowledgeBuilderMock(KNOWLEDGE_BUILDER));
final MiningModelCompilationDTO compilationDTO = MiningModelCompilationDTO.fromCompilationDTO(source);
final KiePMMLMiningModel retrieved = KiePMMLMiningModelFactory.getKiePMMLMiningModel(compilationDTO);
assertNotNull(retrieved);
assertEquals(MINING_MODEL.getAlgorithmName(), retrieved.getAlgorithmName());
assertEquals(MINING_MODEL.isScorable(), retrieved.isScorable());
assertEquals(targetFieldName, retrieved.getTargetField());
}
use of org.kie.pmml.models.mining.model.KiePMMLMiningModel in project drools by kiegroup.
the class PMMLMiningModelEvaluatorTest method validateMiningTargetField.
@Test
public void validateMiningTargetField() {
String name = "NAME";
KiePMMLMiningModel kiePMMLMiningModel = KiePMMLMiningModel.builder(name, Collections.emptyList(), MINING_FUNCTION.ASSOCIATION_RULES).withTargetField("TARGET").build();
evaluator.validateMining(kiePMMLMiningModel);
}
Aggregations