Search in sources :

Example 1 with Extension

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;
}
Also used : Array(org.dmg.pmml.Array) Extension(org.dmg.pmml.Extension) DiscrStats(org.dmg.pmml.DiscrStats) ColumnConfig(ml.shifu.shifu.container.obj.ColumnConfig) UnivariateStats(org.dmg.pmml.UnivariateStats) ModelStats(org.dmg.pmml.ModelStats) BasicFloatNetwork(ml.shifu.shifu.core.dtrain.dataset.BasicFloatNetwork)

Example 2 with Extension

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;
}
Also used : Extension(org.dmg.pmml.Extension) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ContStats(org.dmg.pmml.ContStats) Interval(org.dmg.pmml.Interval)

Example 3 with Extension

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;
}
Also used : Extension(org.dmg.pmml.Extension) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with Extension

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;
}
Also used : Extension(org.dmg.pmml.Extension) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Extension (org.dmg.pmml.Extension)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)2 ColumnConfig (ml.shifu.shifu.container.obj.ColumnConfig)1 BasicFloatNetwork (ml.shifu.shifu.core.dtrain.dataset.BasicFloatNetwork)1 Array (org.dmg.pmml.Array)1 ContStats (org.dmg.pmml.ContStats)1 DiscrStats (org.dmg.pmml.DiscrStats)1 Interval (org.dmg.pmml.Interval)1 ModelStats (org.dmg.pmml.ModelStats)1 UnivariateStats (org.dmg.pmml.UnivariateStats)1