use of org.dmg.pmml.DiscretizeBin in project jpmml-r by jpmml.
the class FormulaUtil method createDiscretize.
private static Discretize createDiscretize(FieldName 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.DiscretizeBin in project jpmml-sparkml by jpmml.
the class BucketizerConverter method encodeFeatures.
@Override
public List<Feature> encodeFeatures(SparkMLEncoder encoder) {
Bucketizer transformer = getTransformer();
Feature feature = encoder.getOnlyFeature(transformer.getInputCol());
ContinuousFeature continuousFeature = feature.toContinuousFeature();
Discretize discretize = new Discretize(continuousFeature.getName());
List<String> categories = new ArrayList<>();
double[] splits = transformer.getSplits();
for (int i = 0; i < (splits.length - 1); i++) {
String category = String.valueOf(i);
categories.add(category);
Interval interval = new Interval((i < (splits.length - 2)) ? Interval.Closure.CLOSED_OPEN : Interval.Closure.CLOSED_CLOSED).setLeftMargin(formatMargin(splits[i])).setRightMargin(formatMargin(splits[i + 1]));
DiscretizeBin discretizeBin = new DiscretizeBin(category, interval);
discretize.addDiscretizeBins(discretizeBin);
}
DerivedField derivedField = encoder.createDerivedField(formatName(transformer), OpType.CATEGORICAL, DataType.INTEGER, discretize);
return Collections.<Feature>singletonList(new CategoricalFeature(encoder, derivedField, categories));
}
use of org.dmg.pmml.DiscretizeBin in project drools by kiegroup.
the class KiePMMLDiscretizeBinInstanceFactoryTest method getKiePMMLDiscretizeBin.
@Test
public void getKiePMMLDiscretizeBin() {
DiscretizeBin toConvert = getRandomDiscretizeBin();
KiePMMLDiscretizeBin retrieved = KiePMMLDiscretizeBinInstanceFactory.getKiePMMLDiscretizeBin(toConvert);
commonVerifyKiePMMLDiscretizeBin(retrieved, toConvert);
}
use of org.dmg.pmml.DiscretizeBin in project drools by kiegroup.
the class KiePMMLDiscretizeFactoryTest method getDiscretizeVariableDeclaration.
@Test
public void getDiscretizeVariableDeclaration() throws IOException {
String variableName = "variableName";
Discretize discretize = new Discretize();
discretize.setField(FieldName.create(NAME));
discretize.setDataType(dataType);
discretize.setMapMissingTo(MAP_MISSING_TO);
discretize.setDefaultValue(DEFAULTVALUE);
discretize.addDiscretizeBins(discretizeBins.toArray(new DiscretizeBin[0]));
BlockStmt retrieved = KiePMMLDiscretizeFactory.getDiscretizeVariableDeclaration(variableName, discretize);
String dataTypeString = getDATA_TYPEString(discretize.getDataType());
String text = getFileContent(TEST_01_SOURCE);
Statement expected = JavaParserUtils.parseBlock(String.format(text, variableName, NAME, MAP_MISSING_TO, DEFAULTVALUE, dataTypeString));
assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
List<Class<?>> imports = Arrays.asList(Arrays.class, Collections.class, KiePMMLDiscretize.class, KiePMMLDiscretizeBin.class, KiePMMLInterval.class);
commonValidateCompilationWithImports(retrieved, imports);
}
use of org.dmg.pmml.DiscretizeBin in project drools by kiegroup.
the class KiePMMLDiscretizeFactoryTest method getDiscretizeBin.
private static DiscretizeBin getDiscretizeBin(Interval interval, String binValue) {
DiscretizeBin toReturn = new DiscretizeBin();
toReturn.setBinValue(binValue);
toReturn.setInterval(interval);
return toReturn;
}
Aggregations