-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved support for DRF and GBM mojo types
- Loading branch information
Showing
16 changed files
with
4,958 additions
and
29 deletions.
There are no files selected for viewing
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
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
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
58 changes: 58 additions & 0 deletions
58
pmml-h2o/src/test/java/org/jpmml/h2o/testing/SegmentationInspector.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,58 @@ | ||
/* | ||
* Copyright (c) 2022 Villu Ruusmann | ||
* | ||
* This file is part of JPMML-H2O | ||
* | ||
* JPMML-H2O 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-H2O 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-H2O. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.jpmml.h2o.testing; | ||
|
||
import java.util.List; | ||
|
||
import org.dmg.pmml.VisitorAction; | ||
import org.dmg.pmml.mining.Segment; | ||
import org.dmg.pmml.mining.Segmentation; | ||
import org.jpmml.model.InvalidElementException; | ||
import org.jpmml.model.visitors.AbstractVisitor; | ||
|
||
public class SegmentationInspector extends AbstractVisitor { | ||
|
||
@Override | ||
public VisitorAction visit(Segmentation segmentation){ | ||
Segmentation.MultipleModelMethod multipleModelMethod = segmentation.getMultipleModelMethod(); | ||
|
||
switch(multipleModelMethod){ | ||
case MAJORITY_VOTE: | ||
case WEIGHTED_MAJORITY_VOTE: | ||
case AVERAGE: | ||
case WEIGHTED_AVERAGE: | ||
case MEDIAN: | ||
case WEIGHTED_MEDIAN: | ||
case SUM: | ||
case WEIGHTED_SUM: | ||
{ | ||
List<Segment> segments = segmentation.getSegments(); | ||
|
||
if(segments.size() <= 1){ | ||
throw new InvalidElementException(segmentation); | ||
} | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
return super.visit(segmentation); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
pmml-h2o/src/test/java/org/jpmml/h2o/testing/TreeMojoModelConverterTest.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,83 @@ | ||
/* | ||
* Copyright (c) 2022 Villu Ruusmann | ||
* | ||
* This file is part of JPMML-H2O | ||
* | ||
* JPMML-H2O 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-H2O 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-H2O. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.jpmml.h2o.testing; | ||
|
||
import java.util.function.Predicate; | ||
|
||
import com.google.common.base.Equivalence; | ||
import org.jpmml.converter.testing.Datasets; | ||
import org.jpmml.converter.testing.Fields; | ||
import org.jpmml.evaluator.ResultField; | ||
import org.jpmml.evaluator.testing.PMMLEquivalence; | ||
import org.jpmml.model.visitors.VisitorBattery; | ||
import org.junit.Test; | ||
|
||
public class TreeMojoModelConverterTest extends H2OEncoderBatchTest implements Datasets, Fields { | ||
|
||
public TreeMojoModelConverterTest(){ | ||
super(new PMMLEquivalence(1e-13, 1e-13)); | ||
} | ||
|
||
@Override | ||
public H2OEncoderBatch createBatch(String algorithm, String dataset, Predicate<ResultField> columnFilter, Equivalence<Object> equivalence){ | ||
H2OEncoderBatch result = new H2OEncoderBatch(algorithm, dataset, columnFilter, equivalence){ | ||
|
||
@Override | ||
public TreeMojoModelConverterTest getArchiveBatchTest(){ | ||
return TreeMojoModelConverterTest.this; | ||
} | ||
|
||
@Override | ||
public VisitorBattery getValidators(){ | ||
VisitorBattery visitorBattery = super.getValidators(); | ||
|
||
visitorBattery.add(SegmentationInspector.class); | ||
|
||
return visitorBattery; | ||
} | ||
}; | ||
|
||
return result; | ||
} | ||
|
||
@Test | ||
public void evaluateAudit() throws Exception { | ||
evaluate("DecisionTree", AUDIT); | ||
} | ||
|
||
@Test | ||
public void evaluateAuditNA() throws Exception { | ||
evaluate("DecisionTree", AUDIT_NA, excludeFields(AUDIT_ADJUSTED)); | ||
} | ||
|
||
@Test | ||
public void evaluateAuto() throws Exception { | ||
evaluate("DecisionTree", AUTO); | ||
} | ||
|
||
@Test | ||
public void evaluateAutoNA() throws Exception { | ||
evaluate("DecisionTree", AUTO_NA); | ||
} | ||
|
||
@Test | ||
public void evaluateIris() throws Exception { | ||
evaluate("DecisionTree", IRIS); | ||
} | ||
} |
Oops, something went wrong.