use of org.dmg.pmml.Interval in project drools by kiegroup.
the class PMMLModelTestUtils method getRandomDiscretizeBin.
public static DiscretizeBin getRandomDiscretizeBin() {
Interval interval = getRandomInterval();
DiscretizeBin toReturn = new DiscretizeBin();
toReturn.setInterval(interval);
toReturn.setBinValue(RandomStringUtils.random(6, true, false));
return toReturn;
}
use of org.dmg.pmml.Interval in project shifu by ShifuML.
the class WoeLocalTransformCreator method createNumericalDerivedField.
/**
* Create @DerivedField for numerical variable
*
* @param config
* - ColumnConfig for numerical variable
* @param cutoff
* - cutoff of normalization
* @param normType
* - the normalization method that is used to generate DerivedField
* @return DerivedField for variable
*/
@Override
protected List<DerivedField> createNumericalDerivedField(ColumnConfig config, double cutoff, ModelNormalizeConf.NormType normType) {
List<Double> binWoeList = (normType.equals(ModelNormalizeConf.NormType.WOE) ? config.getBinCountWoe() : config.getBinWeightedWoe());
List<Double> binBoundaryList = config.getBinBoundary();
List<DiscretizeBin> discretizeBinList = new ArrayList<DiscretizeBin>();
for (int i = 0; i < binBoundaryList.size(); i++) {
DiscretizeBin discretizeBin = new DiscretizeBin();
Interval interval = new Interval();
if (i == 0) {
if (binBoundaryList.size() == 1) {
interval.setClosure(Interval.Closure.OPEN_OPEN).setLeftMargin(Double.NEGATIVE_INFINITY).setRightMargin(Double.POSITIVE_INFINITY);
} else {
interval.setClosure(Interval.Closure.OPEN_OPEN).setRightMargin(binBoundaryList.get(i + 1));
}
} else if (i == binBoundaryList.size() - 1) {
interval.setClosure(Interval.Closure.CLOSED_OPEN).setLeftMargin(binBoundaryList.get(i));
} else {
interval.setClosure(Interval.Closure.CLOSED_OPEN).setLeftMargin(binBoundaryList.get(i)).setRightMargin(binBoundaryList.get(i + 1));
}
discretizeBin.setInterval(interval).setBinValue(Double.toString(binWoeList.get(i)));
discretizeBinList.add(discretizeBin);
}
Discretize discretize = new Discretize();
discretize.setDataType(DataType.DOUBLE).setField(FieldName.create(NormalUtils.getSimpleColumnName(config, columnConfigList, segmentExpansions, datasetHeaders))).setMapMissingTo(Normalizer.normalize(config, null, cutoff, normType).get(0).toString()).setDefaultValue(Normalizer.normalize(config, null, cutoff, normType).get(0).toString()).addDiscretizeBins(discretizeBinList.toArray(new DiscretizeBin[discretizeBinList.size()]));
// derived field name is consisted of FieldName and "_zscl"
List<DerivedField> derivedFields = new ArrayList<DerivedField>();
derivedFields.add(new DerivedField(OpType.CONTINUOUS, DataType.DOUBLE).setName(FieldName.create(genPmmlColumnName(NormalUtils.getSimpleColumnName(config.getColumnName()), normType))).setExpression(discretize));
return derivedFields;
}
use of org.dmg.pmml.Interval in project jpmml-r by jpmml.
the class FormulaUtil method createDiscretize.
private static Discretize createDiscretize(String name, List<String> categories) {
Discretize discretize = new Discretize(name);
for (String category : categories) {
Interval interval = ExpressionTranslator.translateInterval(category);
DiscretizeBin discretizeBin = new DiscretizeBin(category, interval);
discretize.addDiscretizeBins(discretizeBin);
}
return discretize;
}
use of org.dmg.pmml.Interval in project jpmml-r by jpmml.
the class ExpressionTranslatorTest method translateInterval.
@Test
public void translateInterval() {
Interval expected = new Interval(Interval.Closure.OPEN_CLOSED).setLeftMargin(new Double("-10.0E0")).setRightMargin(new Double("+10.0E0"));
Interval actual = ExpressionTranslator.translateInterval("(-10.0E+0, +10.0E-0]");
assertTrue(ReflectionUtil.equals(expected, actual));
try {
ExpressionTranslator.translateInterval("(0, NaN)");
fail();
} catch (IllegalArgumentException iae) {
// Ignored
}
expected = new Interval(Interval.Closure.CLOSED_CLOSED).setLeftMargin(null).setRightMargin(null);
actual = ExpressionTranslator.translateInterval("[-Inf, +Inf]");
assertTrue(ReflectionUtil.equals(expected, actual));
}
Aggregations