use of org.dmg.pmml.Extension in project shifu by ShifuML.
the class ModelStatsCreator method build.
@Override
public ModelStats build(BasicML basicML) {
ModelStats modelStats = new ModelStats();
if (basicML instanceof BasicFloatNetwork) {
BasicFloatNetwork bfn = (BasicFloatNetwork) basicML;
Set<Integer> featureSet = bfn.getFeatureSet();
for (ColumnConfig columnConfig : columnConfigList) {
if (columnConfig.isFinalSelect() && (CollectionUtils.isEmpty(featureSet) || featureSet.contains(columnConfig.getColumnNum()))) {
UnivariateStats univariateStats = new UnivariateStats();
// here, no need to consider if column is in segment expansion
// as we need to address new stats variable
// set simple column name in PMML
univariateStats.setField(FieldName.create(NormalUtils.getSimpleColumnName(columnConfig.getColumnName())));
if (columnConfig.isCategorical()) {
DiscrStats discrStats = new DiscrStats();
Array countArray = createCountArray(columnConfig);
discrStats.addArrays(countArray);
if (!isConcise) {
List<Extension> extensions = createExtensions(columnConfig);
discrStats.addExtensions(extensions.toArray(new Extension[extensions.size()]));
}
univariateStats.setDiscrStats(discrStats);
} else {
// numerical column
univariateStats.setNumericInfo(createNumericInfo(columnConfig));
if (!isConcise) {
univariateStats.setContStats(createConStats(columnConfig));
}
}
modelStats.addUnivariateStats(univariateStats);
}
}
} else {
for (ColumnConfig columnConfig : columnConfigList) {
if (columnConfig.isFinalSelect()) {
UnivariateStats univariateStats = new UnivariateStats();
// here, no need to consider if column is in segment expansion as we need to address new stats
// variable
univariateStats.setField(FieldName.create(NormalUtils.getSimpleColumnName(columnConfig.getColumnName())));
if (columnConfig.isCategorical()) {
DiscrStats discrStats = new DiscrStats();
Array countArray = createCountArray(columnConfig);
discrStats.addArrays(countArray);
if (!isConcise) {
List<Extension> extensions = createExtensions(columnConfig);
discrStats.addExtensions(extensions.toArray(new Extension[extensions.size()]));
}
univariateStats.setDiscrStats(discrStats);
} else {
// numerical column
univariateStats.setNumericInfo(createNumericInfo(columnConfig));
if (!isConcise) {
univariateStats.setContStats(createConStats(columnConfig));
}
}
modelStats.addUnivariateStats(univariateStats);
}
}
}
return modelStats;
}
use of org.dmg.pmml.Extension 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.Extension in project shifu by ShifuML.
the class ModelStatsCreator method createExtensions.
/**
* Create extension list from HashMap
*
* @param extensionMap
* the <String,String> map to create extension list
* @return extension list
*/
private List<Extension> createExtensions(Map<String, String> extensionMap) {
List<Extension> extensions = new ArrayList<Extension>();
for (Map.Entry<String, String> entry : extensionMap.entrySet()) {
String key = entry.getKey();
Extension extension = new Extension();
extension.setName(key);
extension.setValue(entry.getValue());
extensions.add(extension);
}
return extensions;
}
use of org.dmg.pmml.Extension in project shifu by ShifuML.
the class PMMLUtils method createExtensions.
public static List<Extension> createExtensions(Map<String, String> extensionMap) {
List<Extension> extensions = new ArrayList<Extension>();
for (Map.Entry<String, String> entry : extensionMap.entrySet()) {
String key = entry.getKey();
Extension extension = new Extension();
extension.setName(key);
extension.setValue(entry.getValue());
extensions.add(extension);
}
return extensions;
}
Aggregations