Search in sources :

Example 6 with KiePMMLMiningModel

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));
}
Also used : PMML4Result(org.kie.api.pmml.PMML4Result) KiePMMLMiningModel(org.kie.pmml.models.mining.model.KiePMMLMiningModel) ArrayList(java.util.ArrayList) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) LinkedHashMap(java.util.LinkedHashMap) PMMLContextTest(org.kie.pmml.commons.testingutility.PMMLContextTest) KiePMMLSegmentation(org.kie.pmml.models.mining.model.segmentation.KiePMMLSegmentation) PMMLContextTest(org.kie.pmml.commons.testingutility.PMMLContextTest) Test(org.junit.Test)

Example 7 with KiePMMLMiningModel

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);
    }
}
Also used : KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) KiePMMLMiningModel(org.kie.pmml.models.mining.model.KiePMMLMiningModel) ArrayList(java.util.ArrayList) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) KiePMMLInternalException(org.kie.pmml.api.exceptions.KiePMMLInternalException) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException)

Example 8 with KiePMMLMiningModel

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());
}
Also used : HasKnowledgeBuilderMock(org.kie.pmml.models.mining.compiler.HasKnowledgeBuilderMock) KiePMMLMiningModel(org.kie.pmml.models.mining.model.KiePMMLMiningModel) MiningModel(org.dmg.pmml.mining.MiningModel) KiePMMLMiningModel(org.kie.pmml.models.mining.model.KiePMMLMiningModel) MiningModelCompilationDTO(org.kie.pmml.models.mining.compiler.dto.MiningModelCompilationDTO) Test(org.junit.Test)

Example 9 with KiePMMLMiningModel

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);
}
Also used : KiePMMLMiningModel(org.kie.pmml.models.mining.model.KiePMMLMiningModel) PMMLContextTest(org.kie.pmml.commons.testingutility.PMMLContextTest) Test(org.junit.Test)

Aggregations

KiePMMLMiningModel (org.kie.pmml.models.mining.model.KiePMMLMiningModel)9 Test (org.junit.Test)7 PMMLContextTest (org.kie.pmml.commons.testingutility.PMMLContextTest)6 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)2 MiningModel (org.dmg.pmml.mining.MiningModel)2 PMML4Result (org.kie.api.pmml.PMML4Result)2 KiePMMLNameValue (org.kie.pmml.commons.model.tuples.KiePMMLNameValue)2 HasKnowledgeBuilderMock (org.kie.pmml.models.mining.compiler.HasKnowledgeBuilderMock)2 KiePMMLSegmentation (org.kie.pmml.models.mining.model.segmentation.KiePMMLSegmentation)2 Serializable (java.io.Serializable)1 PMML (org.dmg.pmml.PMML)1 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)1 KiePMMLException (org.kie.pmml.api.exceptions.KiePMMLException)1 KiePMMLInternalException (org.kie.pmml.api.exceptions.KiePMMLInternalException)1 KiePMMLModel (org.kie.pmml.commons.model.KiePMMLModel)1 MiningModelCompilationDTO (org.kie.pmml.models.mining.compiler.dto.MiningModelCompilationDTO)1