use of org.dmg.pmml.Interval in project openscoring by openscoring.
the class ModelUtil method encodeValues.
private static List<String> encodeValues(DataField dataField) {
List<String> result = new ArrayList<>();
List<Interval> intervals = dataField.getIntervals();
for (Interval interval : intervals) {
StringBuilder sb = new StringBuilder();
Double leftMargin = interval.getLeftMargin();
sb.append(Double.toString(leftMargin != null ? leftMargin : Double.NEGATIVE_INFINITY));
sb.append(", ");
Double rightMargin = interval.getRightMargin();
sb.append(Double.toString(rightMargin != null ? rightMargin : Double.POSITIVE_INFINITY));
String value = sb.toString();
Interval.Closure closure = interval.getClosure();
switch(closure) {
case OPEN_OPEN:
result.add("(" + value + ")");
break;
case OPEN_CLOSED:
result.add("(" + value + "]");
break;
case CLOSED_OPEN:
result.add("[" + value + ")");
break;
case CLOSED_CLOSED:
result.add("[" + value + "]");
break;
default:
break;
}
}
List<Value> values = dataField.getValues();
for (Value value : values) {
Value.Property property = value.getProperty();
switch(property) {
case VALID:
result.add(value.getValue());
break;
default:
break;
}
}
return result;
}
use of org.dmg.pmml.Interval in project shifu by ShifuML.
the class ModelStatsCreator method createConStats.
/**
* Create @ConStats for numerical variable
*
* @param columnConfig
* - ColumnConfig to generate ConStats
* @return ConStats for variable
*/
private ContStats createConStats(ColumnConfig columnConfig) {
ContStats conStats = new ContStats();
List<Interval> intervals = new ArrayList<Interval>();
for (int i = 0; i < columnConfig.getBinBoundary().size(); i++) {
Interval interval = new Interval();
interval.setClosure(Interval.Closure.OPEN_CLOSED);
interval.setLeftMargin(columnConfig.getBinBoundary().get(i));
if (i == columnConfig.getBinBoundary().size() - 1) {
interval.setRightMargin(Double.POSITIVE_INFINITY);
} else {
interval.setRightMargin(columnConfig.getBinBoundary().get(i + 1));
}
intervals.add(interval);
}
conStats.addIntervals(intervals.toArray(new Interval[intervals.size()]));
Map<String, String> extensionMap = new HashMap<String, String>();
extensionMap.put("BinCountPos", columnConfig.getBinCountPos().toString());
extensionMap.put("BinCountNeg", columnConfig.getBinCountNeg().toString());
extensionMap.put("BinWeightedCountPos", columnConfig.getBinWeightedPos().toString());
extensionMap.put("BinWeightedCountNeg", columnConfig.getBinWeightedNeg().toString());
extensionMap.put("BinPosRate", columnConfig.getBinPosRate().toString());
extensionMap.put("BinWOE", calculateWoe(columnConfig.getBinCountPos(), columnConfig.getBinCountNeg()).toString());
extensionMap.put("KS", Double.toString(columnConfig.getKs()));
extensionMap.put("IV", Double.toString(columnConfig.getIv()));
List<Extension> extensions = createExtensions(extensionMap);
conStats.addExtensions(extensions.toArray(new Extension[extensions.size()]));
return conStats;
}
use of org.dmg.pmml.Interval in project drools by kiegroup.
the class KiePMMLIntervalInstanceFactoryTest method getKiePMMLInterval.
@Test
public void getKiePMMLInterval() {
Interval toConvert = getRandomInterval();
KiePMMLInterval retrieved = KiePMMLIntervalInstanceFactory.getKiePMMLInterval(toConvert);
commonVerifyKiePMMLInterval(retrieved, toConvert);
}
use of org.dmg.pmml.Interval 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.Interval 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));
}
Aggregations