-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
220 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
pmml-evaluator/src/test/java/org/jpmml/evaluator/mining/GradientBoosterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (c) 2022 Villu Ruusmann | ||
* | ||
* This file is part of JPMML-Evaluator | ||
* | ||
* JPMML-Evaluator is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* JPMML-Evaluator is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with JPMML-Evaluator. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.jpmml.evaluator.mining; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
import org.dmg.pmml.mining.Segmentation; | ||
import org.jpmml.evaluator.MissingFieldValueException; | ||
import org.jpmml.evaluator.ModelEvaluator; | ||
import org.jpmml.evaluator.ModelEvaluatorTest; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.fail; | ||
|
||
public class GradientBoosterTest extends ModelEvaluatorTest { | ||
|
||
@Test | ||
public void evaluate() throws Exception { | ||
ModelEvaluator<?> evaluator = createModelEvaluator(); | ||
|
||
checkResultFields(Arrays.asList("y"), Arrays.asList("probability(event)", "probability(no event)"), evaluator); | ||
|
||
Map<String, ?> arguments = Collections.emptyMap(); | ||
|
||
Map<String, ?> results; | ||
|
||
try { | ||
results = evaluator.evaluate(arguments); | ||
|
||
fail(); | ||
} catch(MissingFieldValueException mfve){ | ||
// Ignored | ||
} | ||
|
||
evaluator = createModelEvaluator(new MissingPredictionTreatmentTransformer(Segmentation.MissingPredictionTreatment.RETURN_MISSING)); | ||
|
||
results = evaluator.evaluate(arguments); | ||
|
||
assertTrue(results.containsKey("y")); | ||
assertNull(results.get("y")); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...uator/src/test/java/org/jpmml/evaluator/mining/MissingPredictionTreatmentTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (c) 2022 Villu Ruusmann | ||
* | ||
* This file is part of JPMML-Evaluator | ||
* | ||
* JPMML-Evaluator is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* JPMML-Evaluator is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with JPMML-Evaluator. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.jpmml.evaluator.mining; | ||
|
||
import org.dmg.pmml.PMML; | ||
import org.dmg.pmml.Visitor; | ||
import org.dmg.pmml.VisitorAction; | ||
import org.dmg.pmml.mining.Segmentation; | ||
import org.jpmml.evaluator.PMMLTransformer; | ||
import org.jpmml.model.visitors.AbstractVisitor; | ||
|
||
public class MissingPredictionTreatmentTransformer implements PMMLTransformer<RuntimeException> { | ||
|
||
private Segmentation.MissingPredictionTreatment missingPredictionTreatment; | ||
|
||
|
||
public MissingPredictionTreatmentTransformer(Segmentation.MissingPredictionTreatment missingPredictionTreatment){ | ||
setMissingPredictionTreatment(missingPredictionTreatment); | ||
} | ||
|
||
@Override | ||
public PMML apply(PMML pmml){ | ||
Visitor visitor = new AbstractVisitor(){ | ||
|
||
@Override | ||
public VisitorAction visit(Segmentation segmentation){ | ||
segmentation.setMissingPredictionTreatment(getMissingPredictionTreatment()); | ||
|
||
return super.visit(segmentation); | ||
} | ||
}; | ||
|
||
visitor.applyTo(pmml); | ||
|
||
return pmml; | ||
} | ||
|
||
public Segmentation.MissingPredictionTreatment getMissingPredictionTreatment(){ | ||
return this.missingPredictionTreatment; | ||
} | ||
|
||
private void setMissingPredictionTreatment(Segmentation.MissingPredictionTreatment missingPredictionTreatment){ | ||
this.missingPredictionTreatment = missingPredictionTreatment; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
pmml-evaluator/src/test/resources/pmml/mining/GradientBoosterTest.pmml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?xml version="1.0" ?> | ||
<PMML xmlns="http://www.dmg.org/PMML-4_4" version="4.4"> | ||
<DataDictionary> | ||
<DataField name="x" optype="continuous" dataType="double"/> | ||
<DataField name="y" optype="categorical" dataType="string"> | ||
<Value value="event"/> | ||
<Value value="no event"/> | ||
</DataField> | ||
</DataDictionary> | ||
<MiningModel functionName="classification"> | ||
<MiningSchema> | ||
<MiningField name="x"/> | ||
<MiningField name="y" usageType="target"/> | ||
</MiningSchema> | ||
<Segmentation multipleModelMethod="modelChain"> | ||
<Segment> | ||
<True/> | ||
<MiningModel functionName="regression"> | ||
<MiningSchema> | ||
<MiningField name="x"/> | ||
</MiningSchema> | ||
<Output> | ||
<OutputField name="decisionFunction(event)" feature="predictedValue"/> | ||
</Output> | ||
<Segmentation multipleModelMethod="sum"> | ||
<Segment> | ||
<True/> | ||
<RegressionModel functionName="regression"> | ||
<MiningSchema> | ||
<MiningField name="x"/> | ||
</MiningSchema> | ||
<RegressionTable intercept="0.0"> | ||
<NumericPredictor name="x" coefficient="2"/> | ||
</RegressionTable> | ||
</RegressionModel> | ||
</Segment> | ||
<Segment> | ||
<True/> | ||
<RegressionModel functionName="regression"> | ||
<MiningSchema> | ||
<MiningField name="x"/> | ||
</MiningSchema> | ||
<RegressionTable intercept="0.0"> | ||
<NumericPredictor name="x" coefficient="1"/> | ||
</RegressionTable> | ||
</RegressionModel> | ||
</Segment> | ||
<Segment> | ||
<True/> | ||
<RegressionModel functionName="regression"> | ||
<MiningSchema> | ||
<MiningField name="x"/> | ||
</MiningSchema> | ||
<RegressionTable intercept="0.0"> | ||
<NumericPredictor name="x" coefficient="0.5"/> | ||
</RegressionTable> | ||
</RegressionModel> | ||
</Segment> | ||
</Segmentation> | ||
</MiningModel> | ||
</Segment> | ||
<Segment> | ||
<True/> | ||
<RegressionModel functionName="classification"> | ||
<MiningSchema> | ||
<MiningField name="decisionFunction(event)"/> | ||
<MiningField name="y" usageType="target"/> | ||
</MiningSchema> | ||
<Output> | ||
<OutputField name="probability(event)" optype="continuous" dataType="double" feature="probability" value="event"/> | ||
<OutputField name="probability(no event)" optype="continuous" dataType="double" feature="probability" value="no event"/> | ||
</Output> | ||
<RegressionTable targetCategory="event" intercept="0.0"> | ||
<NumericPredictor field="decisionFunction(event)" coefficient="1"/> | ||
</RegressionTable> | ||
<RegressionTable targetCategory="no event" intercept="0.0"/> | ||
</RegressionModel> | ||
</Segment> | ||
</Segmentation> | ||
</MiningModel> | ||
</PMML> | ||
|
||
|