Search in sources :

Example 26 with DerivedField

use of org.dmg.pmml.DerivedField in project shifu by ShifuML.

the class ZscoreLocalTransformCreator method build.

@Override
public LocalTransformations build(BasicML basicML) {
    LocalTransformations localTransformations = new LocalTransformations();
    if (basicML instanceof BasicFloatNetwork) {
        BasicFloatNetwork bfn = (BasicFloatNetwork) basicML;
        Set<Integer> featureSet = bfn.getFeatureSet();
        for (ColumnConfig config : columnConfigList) {
            if (config.isFinalSelect() && (CollectionUtils.isEmpty(featureSet) || featureSet.contains(config.getColumnNum()))) {
                double cutoff = modelConfig.getNormalizeStdDevCutOff();
                List<DerivedField> deriviedFields = config.isCategorical() ? createCategoricalDerivedField(config, cutoff, modelConfig.getNormalizeType()) : createNumericalDerivedField(config, cutoff, modelConfig.getNormalizeType());
                localTransformations.addDerivedFields(deriviedFields.toArray(new DerivedField[deriviedFields.size()]));
            }
        }
    } else {
        for (ColumnConfig config : columnConfigList) {
            if (config.isFinalSelect()) {
                double cutoff = modelConfig.getNormalizeStdDevCutOff();
                List<DerivedField> deriviedFields = config.isCategorical() ? createCategoricalDerivedField(config, cutoff, modelConfig.getNormalizeType()) : createNumericalDerivedField(config, cutoff, modelConfig.getNormalizeType());
                localTransformations.addDerivedFields(deriviedFields.toArray(new DerivedField[deriviedFields.size()]));
            }
        }
    }
    return localTransformations;
}
Also used : LocalTransformations(org.dmg.pmml.LocalTransformations) ColumnConfig(ml.shifu.shifu.container.obj.ColumnConfig) BasicFloatNetwork(ml.shifu.shifu.core.dtrain.dataset.BasicFloatNetwork) DerivedField(org.dmg.pmml.DerivedField)

Example 27 with DerivedField

use of org.dmg.pmml.DerivedField in project shifu by ShifuML.

the class NeuralNetworkModelIntegrator method getNeuralInputs.

private NeuralInputs getNeuralInputs(final NeuralNetwork model) {
    NeuralInputs nnInputs = new NeuralInputs();
    // get HashMap for local transform and MiningSchema fields
    HashMap<FieldName, FieldName> reversMiningTransformMap = new HashMap<FieldName, FieldName>();
    HashMap<FieldName, List<FieldName>> treeMapOfTransform = new HashMap<FieldName, List<FieldName>>();
    for (DerivedField dField : model.getLocalTransformations().getDerivedFields()) {
        // Apply z-scale normalization on numerical variables
        FieldName parentField = null;
        if (dField.getExpression() instanceof NormContinuous) {
            parentField = ((NormContinuous) dField.getExpression()).getField();
            reversMiningTransformMap.put(dField.getName(), parentField);
        } else // Apply bin map on categorical variables
        if (dField.getExpression() instanceof MapValues) {
            parentField = ((MapValues) dField.getExpression()).getFieldColumnPairs().get(0).getField();
            reversMiningTransformMap.put(dField.getName(), parentField);
        } else if (dField.getExpression() instanceof Discretize) {
            parentField = ((Discretize) dField.getExpression()).getField();
            reversMiningTransformMap.put(dField.getName(), parentField);
        }
        List<FieldName> fieldNames = treeMapOfTransform.get(parentField);
        if (fieldNames == null) {
            fieldNames = new ArrayList<FieldName>();
        }
        fieldNames.add(dField.getName());
        treeMapOfTransform.put(parentField, fieldNames);
    }
    // comment here
    List<MiningField> miningList = model.getMiningSchema().getMiningFields();
    int index = 0;
    for (DerivedField dField : model.getLocalTransformations().getDerivedFields()) {
        List<FieldName> list = treeMapOfTransform.get(dField.getName());
        boolean isLeaf = (list == null || list.size() == 0);
        FieldName root = getRoot(dField.getName(), reversMiningTransformMap);
        if (isLeaf && isRootInMiningList(root, miningList)) {
            DerivedField field = new DerivedField(OpType.CONTINUOUS, DataType.DOUBLE).setName(dField.getName()).setExpression(new FieldRef(dField.getName()));
            nnInputs.addNeuralInputs(new NeuralInput("0," + (index++), field));
        }
    }
    DerivedField field = new DerivedField(OpType.CONTINUOUS, DataType.DOUBLE).setName(new FieldName(PluginConstants.biasValue)).setExpression(new FieldRef(new FieldName(PluginConstants.biasValue)));
    nnInputs.addNeuralInputs(new NeuralInput(PluginConstants.biasValue, field));
    return nnInputs;
}
Also used : NormContinuous(org.dmg.pmml.NormContinuous) MiningField(org.dmg.pmml.MiningField) FieldRef(org.dmg.pmml.FieldRef) NeuralInputs(org.dmg.pmml.neural_network.NeuralInputs) HashMap(java.util.HashMap) MapValues(org.dmg.pmml.MapValues) Discretize(org.dmg.pmml.Discretize) ArrayList(java.util.ArrayList) List(java.util.List) FieldName(org.dmg.pmml.FieldName) DerivedField(org.dmg.pmml.DerivedField) NeuralInput(org.dmg.pmml.neural_network.NeuralInput)

Aggregations

DerivedField (org.dmg.pmml.DerivedField)27 ArrayList (java.util.ArrayList)16 Feature (org.jpmml.converter.Feature)14 ContinuousFeature (org.jpmml.converter.ContinuousFeature)13 FieldName (org.dmg.pmml.FieldName)10 Apply (org.dmg.pmml.Apply)9 Expression (org.dmg.pmml.Expression)8 NormContinuous (org.dmg.pmml.NormContinuous)6 CategoricalFeature (org.jpmml.converter.CategoricalFeature)5 DataField (org.dmg.pmml.DataField)4 Discretize (org.dmg.pmml.Discretize)4 MapValues (org.dmg.pmml.MapValues)4 Vector (org.apache.spark.ml.linalg.Vector)3 FieldRef (org.dmg.pmml.FieldRef)3 LocalTransformations (org.dmg.pmml.LocalTransformations)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Constant (org.dmg.pmml.Constant)2 DiscretizeBin (org.dmg.pmml.DiscretizeBin)2