use of org.dmg.pmml.MiningField in project shifu by ShifuML.
the class TreeModelMiningSchemaCreator method build.
@Override
public MiningSchema build(BasicML basicML) {
MiningSchema miningSchema = new MiningSchema();
for (ColumnConfig columnConfig : columnConfigList) {
if (columnConfig.isFinalSelect() || columnConfig.isTarget()) {
MiningField miningField = new MiningField();
// TODO, how to support segment variable in tree model, here should be changed
miningField.setName(FieldName.create(NormalUtils.getSimpleColumnName(columnConfig.getColumnName())));
miningField.setOpType(getOptype(columnConfig));
if (columnConfig.isNumerical()) {
miningField.setMissingValueReplacement(String.valueOf(columnConfig.getColumnStats().getMean()));
} else {
miningField.setMissingValueReplacement("");
}
if (columnConfig.isFinalSelect()) {
miningField.setUsageType(UsageType.ACTIVE);
} else if (columnConfig.isTarget()) {
miningField.setUsageType(UsageType.TARGET);
}
miningSchema.addMiningFields(miningField);
}
}
return miningSchema;
}
use of org.dmg.pmml.MiningField in project shifu by ShifuML.
the class MiningSchemaCreator method build.
@Override
public MiningSchema build(BasicML basicML) {
MiningSchema miningSchema = new MiningSchema();
boolean isSegExpansionMode = columnConfigList.size() > datasetHeaders.length;
int segSize = segmentExpansions.size();
if (basicML != null && basicML instanceof BasicFloatNetwork) {
BasicFloatNetwork bfn = (BasicFloatNetwork) basicML;
Set<Integer> featureSet = bfn.getFeatureSet();
for (ColumnConfig columnConfig : columnConfigList) {
if (columnConfig.getColumnNum() >= datasetHeaders.length) {
// in order
break;
}
if (isActiveColumn(featureSet, columnConfig)) {
if (columnConfig.isTarget()) {
List<MiningField> miningFields = createTargetMingFields(columnConfig);
miningSchema.addMiningFields(miningFields.toArray(new MiningField[miningFields.size()]));
} else {
miningSchema.addMiningFields(createActiveMingFields(columnConfig));
}
} else if (isSegExpansionMode) {
// even current column not selected, if segment column selected, we should keep raw column
for (int i = 0; i < segSize; i++) {
int newIndex = datasetHeaders.length * (i + 1) + columnConfig.getColumnNum();
ColumnConfig cc = columnConfigList.get(newIndex);
if (cc.isFinalSelect()) {
// if one segment feature is selected, we should put raw column in
if (columnConfig.isTarget()) {
List<MiningField> miningFields = createTargetMingFields(columnConfig);
miningSchema.addMiningFields(miningFields.toArray(new MiningField[miningFields.size()]));
} else {
miningSchema.addMiningFields(createActiveMingFields(columnConfig));
}
break;
}
}
}
}
} else {
for (ColumnConfig columnConfig : columnConfigList) {
if (columnConfig.getColumnNum() >= datasetHeaders.length) {
// in order
break;
}
// FIXME, if no variable is selected
if (columnConfig.isFinalSelect() || columnConfig.isTarget()) {
if (columnConfig.isTarget()) {
List<MiningField> miningFields = createTargetMingFields(columnConfig);
miningSchema.addMiningFields(miningFields.toArray(new MiningField[miningFields.size()]));
} else {
miningSchema.addMiningFields(createActiveMingFields(columnConfig));
}
} else if (isSegExpansionMode) {
// even current column not selected, if segment column selected, we should keep raw column
for (int i = 0; i < segSize; i++) {
int newIndex = datasetHeaders.length * (i + 1) + columnConfig.getColumnNum();
ColumnConfig cc = columnConfigList.get(newIndex);
if (cc.isFinalSelect()) {
// if one segment feature is selected, we should put raw column in
if (columnConfig.isTarget()) {
List<MiningField> miningFields = createTargetMingFields(columnConfig);
miningSchema.addMiningFields(miningFields.toArray(new MiningField[miningFields.size()]));
} else {
miningSchema.addMiningFields(createActiveMingFields(columnConfig));
}
break;
}
}
}
}
}
return miningSchema;
}
use of org.dmg.pmml.MiningField 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;
}
use of org.dmg.pmml.MiningField in project shifu by ShifuML.
the class NeuralNetworkModelIntegrator method isRootInMiningList.
private boolean isRootInMiningList(FieldName root, List<MiningField> miningList) {
for (int i = 0; i < miningList.size(); i++) {
MiningField mField = miningList.get(i);
if (mField.getUsageType() != MiningField.UsageType.ACTIVE)
continue;
FieldName mFieldName = mField.getName();
if (root.equals(mFieldName)) {
return true;
}
}
return false;
}
Aggregations