Search in sources :

Example 1 with KiePMMLMiningModel

use of org.kie.pmml.models.mining.model.KiePMMLMiningModel in project drools by kiegroup.

the class MiningModelImplementationProviderTest method commonGetKiePMMLModel.

private void commonGetKiePMMLModel(String source) throws Exception {
    final PMML pmml = getPMML(source);
    final KnowledgeBuilderImpl knowledgeBuilder = new KnowledgeBuilderImpl();
    final MiningModel miningmodel = (MiningModel) pmml.getModels().get(0);
    final CommonCompilationDTO<MiningModel> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, miningmodel, new HasKnowledgeBuilderMock(knowledgeBuilder));
    final KiePMMLMiningModel retrieved = PROVIDER.getKiePMMLModel(compilationDTO);
    assertNotNull(retrieved);
    assertTrue(retrieved instanceof Serializable);
    commonVerifyIsDeepCloneable(retrieved);
}
Also used : Serializable(java.io.Serializable) HasKnowledgeBuilderMock(org.kie.pmml.models.mining.compiler.HasKnowledgeBuilderMock) KiePMMLMiningModel(org.kie.pmml.models.mining.model.KiePMMLMiningModel) MiningModel(org.dmg.pmml.mining.MiningModel) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) KiePMMLMiningModel(org.kie.pmml.models.mining.model.KiePMMLMiningModel) PMML(org.dmg.pmml.PMML)

Example 2 with KiePMMLMiningModel

use of org.kie.pmml.models.mining.model.KiePMMLMiningModel in project drools by kiegroup.

the class PMMLMiningModelEvaluatorTest method getPMML4ResultFAIL.

@Test
public void getPMML4ResultFAIL() {
    String name = "NAME";
    String targetField = "TARGET";
    KiePMMLSegmentation kiePMMLSegmentation = KiePMMLSegmentation.builder("SEGM_1", Collections.emptyList(), AVERAGE).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", "FIRST_VALUE"), 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(FAIL.getName(), retrieved.getResultCode());
    assertEquals(targetField, retrieved.getResultObjectName());
    final Map<String, Object> resultVariables = retrieved.getResultVariables();
    assertTrue(resultVariables.containsKey(targetField));
    assertNull(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 3 with KiePMMLMiningModel

use of org.kie.pmml.models.mining.model.KiePMMLMiningModel in project drools by kiegroup.

the class PMMLMiningModelEvaluatorTest method validateKiePMMLMiningModel.

@Test
public void validateKiePMMLMiningModel() {
    String name = "NAME";
    KiePMMLMiningModel kiePMMLMiningModel = KiePMMLMiningModel.builder(name, Collections.emptyList(), MINING_FUNCTION.ASSOCIATION_RULES).withTargetField("TARGET").build();
    evaluator.validate(kiePMMLMiningModel);
}
Also used : KiePMMLMiningModel(org.kie.pmml.models.mining.model.KiePMMLMiningModel) PMMLContextTest(org.kie.pmml.commons.testingutility.PMMLContextTest) Test(org.junit.Test)

Example 4 with KiePMMLMiningModel

use of org.kie.pmml.models.mining.model.KiePMMLMiningModel in project drools by kiegroup.

the class PMMLMiningModelEvaluatorTest method validateMiningEmptyTargetField.

@Test(expected = KiePMMLInternalException.class)
public void validateMiningEmptyTargetField() {
    String name = "NAME";
    KiePMMLMiningModel kiePMMLMiningModel = KiePMMLMiningModel.builder(name, Collections.emptyList(), MINING_FUNCTION.ASSOCIATION_RULES).withTargetField("     ").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)

Example 5 with KiePMMLMiningModel

use of org.kie.pmml.models.mining.model.KiePMMLMiningModel in project drools by kiegroup.

the class PMMLMiningModelEvaluatorTest method validateMiningNoTargetField.

@Test(expected = KiePMMLInternalException.class)
public void validateMiningNoTargetField() {
    String name = "NAME";
    KiePMMLMiningModel kiePMMLMiningModel = KiePMMLMiningModel.builder(name, Collections.emptyList(), MINING_FUNCTION.ASSOCIATION_RULES).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