本文整理汇总了Java中org.dmg.pmml.DerivedField类的典型用法代码示例。如果您正苦于以下问题:Java DerivedField类的具体用法?Java DerivedField怎么用?Java DerivedField使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DerivedField类属于org.dmg.pmml包,在下文中一共展示了DerivedField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDerivedFields
import org.dmg.pmml.DerivedField; //导入依赖的package包/类
public static String getDerivedFields(String fieldName, List<DerivedField> allDerivedFields, List<DerivedField>
derivedFields) {
// trace back all derived fields until we must arrive at an actual data field. This unfortunately means we have to
// loop over dervived fields as often as we find one..
DerivedField lastFoundDerivedField;
String lastFieldName = fieldName;
do {
lastFoundDerivedField = null;
for (DerivedField derivedField : allDerivedFields) {
if (derivedField.getName().getValue().equals(lastFieldName)) {
lastFoundDerivedField = derivedField;
derivedFields.add(derivedField);
// now get the next fieldname this field references
// this is tricky, because this information can be anywhere...
lastFieldName = getReferencedFieldName(derivedField);
lastFoundDerivedField = derivedField;
}
}
} while (lastFoundDerivedField != null);
return lastFieldName;
}
示例2: getFieldValuesList
import org.dmg.pmml.DerivedField; //导入依赖的package包/类
protected static List<VectorRange> getFieldValuesList(TreeModel treeModel, DataDictionary dataDictionary,
TransformationDictionary transformationDictionary) {
// walk the tree model and gather all the field name
Set<String> fieldNames = new HashSet<>();
Node startNode = treeModel.getNode();
getFieldNamesFromNode(fieldNames, startNode);
// create the actual VectorRange objects, copy paste much from GLMHelper
List<VectorRange> fieldsToValues = new ArrayList<>();
List<DerivedField> allDerivedFields = ProcessPMMLHelper.getAllDerivedFields(treeModel, transformationDictionary);
for(String fieldName : fieldNames) {
List<DerivedField> derivedFields = new ArrayList<>();
String rawFieldName = ProcessPMMLHelper.getDerivedFields(fieldName, allDerivedFields, derivedFields);
DataField rawField = ProcessPMMLHelper.getRawDataField(dataDictionary, rawFieldName);
MiningField miningField = ProcessPMMLHelper.getMiningField(treeModel, rawFieldName);
fieldsToValues.add(new PMMLVectorRange.FieldToValue(rawField, miningField, derivedFields.toArray(new
DerivedField[derivedFields.size()])));
}
return fieldsToValues;
}
示例3: fillPreProcessingSteps
import org.dmg.pmml.DerivedField; //导入依赖的package包/类
protected void fillPreProcessingSteps(DerivedField[] derivedFields) {
int derivedFieldIndex = derivedFields.length - 1;
// don't start at the beginning, we might have a pre processing step there already from the mining field
for (int preProcessingStepIndex = preProcessingSteps.length - derivedFields.length; preProcessingStepIndex < preProcessingSteps
.length;
preProcessingStepIndex++) {
DerivedField derivedField = derivedFields[derivedFieldIndex];
if (derivedField.getExpression() != null) {
handleExpression(preProcessingStepIndex, derivedField);
} else {
throw new UnsupportedOperationException("So far only Apply implemented.");
}
derivedFieldIndex--;
}
}
示例4: handleExpression
import org.dmg.pmml.DerivedField; //导入依赖的package包/类
private void handleExpression(int preProcessingStepIndex, DerivedField derivedField) {
if (derivedField.getExpression() instanceof Apply) {
for (Expression expression : ((Apply) derivedField.getExpression()).getExpressions()) {
if (expression instanceof Apply) {
if (((Apply) expression).getFunction().equals("isMissing")) {
// now find the value that is supposed to replace the missing value
for (Expression expression2 : ((Apply) derivedField.getExpression()).getExpressions()) {
if (expression2 instanceof Constant) {
String missingValue = ((Constant) expression2).getValue();
preProcessingSteps[preProcessingStepIndex] = new MissingValuePreProcess(derivedField, missingValue);
break;
}
}
} else {
throw new UnsupportedOperationException("So far only if isMissing implemented.");
}
}
}
} else if (derivedField.getExpression() instanceof NormContinuous) {
preProcessingSteps[preProcessingStepIndex] = new NormContinousPreProcess((NormContinuous) derivedField
.getExpression(), derivedField.getName().getValue());
} else {
throw new UnsupportedOperationException("So far only Apply expression implemented.");
}
}
示例5: toContinuousFeature
import org.dmg.pmml.DerivedField; //导入依赖的package包/类
@Override
public ContinuousFeature toContinuousFeature(){
PMMLEncoder encoder = ensureEncoder();
List<? extends Feature> features = getFeatures();
DerivedField derivedField = encoder.getDerivedField(getName());
if(derivedField == null){
Apply apply = PMMLUtil.createApply("*", ((features.get(0)).toContinuousFeature()).ref(), ((features.get(1)).toContinuousFeature()).ref());
for(int i = 2; i < features.size(); i++){
apply = PMMLUtil.createApply("*", apply, ((features.get(i)).toContinuousFeature()).ref());
}
derivedField = encoder.createDerivedField(getName(), OpType.CONTINUOUS, DataType.DOUBLE, apply);
}
return new ContinuousFeature(encoder, derivedField);
}
示例6: createRegressionNeuralOutputs
import org.dmg.pmml.DerivedField; //导入依赖的package包/类
static
public NeuralOutputs createRegressionNeuralOutputs(List<? extends Entity> entities, ContinuousLabel continuousLabel){
if(entities.size() != 1){
throw new IllegalArgumentException();
}
Entity entity = Iterables.getOnlyElement(entities);
DerivedField derivedField = new DerivedField(OpType.CONTINUOUS, continuousLabel.getDataType())
.setExpression(new FieldRef(continuousLabel.getName()));
NeuralOutput neuralOutput = new NeuralOutput()
.setOutputNeuron(entity.getId())
.setDerivedField(derivedField);
NeuralOutputs neuralOutputs = new NeuralOutputs()
.addNeuralOutputs(neuralOutput);
return neuralOutputs;
}
示例7: createClassificationNeuralOutputs
import org.dmg.pmml.DerivedField; //导入依赖的package包/类
static
public NeuralOutputs createClassificationNeuralOutputs(List<? extends Entity> entities, CategoricalLabel categoricalLabel){
if(entities.size() != categoricalLabel.size()){
throw new IllegalArgumentException();
}
NeuralOutputs neuralOutputs = new NeuralOutputs();
for(int i = 0; i < categoricalLabel.size(); i++){
Entity entity = entities.get(i);
DerivedField derivedField = new DerivedField(OpType.CATEGORICAL, categoricalLabel.getDataType())
.setExpression(new NormDiscrete(categoricalLabel.getName(), categoricalLabel.getValue(i)));
NeuralOutput neuralOutput = new NeuralOutput()
.setOutputNeuron(entity.getId())
.setDerivedField(derivedField);
neuralOutputs.addNeuralOutputs(neuralOutput);
}
return neuralOutputs;
}
示例8: toContinuousFeature
import org.dmg.pmml.DerivedField; //导入依赖的package包/类
public ContinuousFeature toContinuousFeature(DataType dataType){
ContinuousFeature continuousFeature = toContinuousFeature();
if((dataType).equals(continuousFeature.getDataType())){
return continuousFeature;
}
PMMLEncoder encoder = ensureEncoder();
FieldName name = FieldName.create((dataType.name()).toLowerCase() + "(" + (continuousFeature.getName()).getValue() + ")");
DerivedField derivedField = encoder.getDerivedField(name);
if(derivedField == null){
derivedField = encoder.createDerivedField(name, OpType.CONTINUOUS, dataType, continuousFeature.ref());
}
return new ContinuousFeature(encoder, derivedField);
}
示例9: filter
import org.dmg.pmml.DerivedField; //导入依赖的package包/类
private Schema filter(Schema schema){
Function<Feature, Feature> function = new Function<Feature, Feature>(){
@Override
public Feature apply(Feature feature){
Expression expression = encodeExpression(feature);
if(expression == null){
return feature;
}
DerivedField derivedField = createDerivedField(FeatureUtil.createName("preProcess", feature), OpType.CONTINUOUS, DataType.DOUBLE, expression);
return new ContinuousFeature(PreProcessEncoder.this, derivedField);
}
};
return schema.toTransformedSchema(function);
}
示例10: prepareInputField
import org.dmg.pmml.DerivedField; //导入依赖的package包/类
static
private FieldName prepareInputField(FunctionExpression.Argument argument, OpType opType, DataType dataType, RExpEncoder encoder){
Expression expression = argument.getExpression();
if(expression instanceof FieldRef){
FieldRef fieldRef = (FieldRef)expression;
return fieldRef.getField();
} else
if(expression instanceof Apply){
Apply apply = (Apply)expression;
DerivedField derivedField = encoder.createDerivedField(FieldName.create((argument.formatExpression()).trim()), opType, dataType, apply);
return derivedField.getName();
} else
{
throw new IllegalArgumentException();
}
}
示例11: resolveField
import org.dmg.pmml.DerivedField; //导入依赖的package包/类
static
private Field resolveField(FieldName name, MiningModelEvaluationContext context){
while(context != null){
OutputField outputField = context.getOutputField(name);
if(outputField != null){
return outputField;
}
DerivedField localDerivedField = context.getLocalDerivedField(name);
if(localDerivedField != null){
return localDerivedField;
}
context = context.getParent();
}
return null;
}
示例12: encodeFeatures
import org.dmg.pmml.DerivedField; //导入依赖的package包/类
@Override
public List<Feature> encodeFeatures(SparkMLEncoder encoder){
PCAModel transformer = getTransformer();
List<Feature> features = encoder.getFeatures(transformer.getInputCol());
DenseMatrix pc = transformer.pc();
if(pc.numRows() != features.size()){
throw new IllegalArgumentException();
}
List<Feature> result = new ArrayList<>();
for(int i = 0; i < transformer.getK(); i++){
Apply apply = new Apply("sum");
for(int j = 0; j < features.size(); j++){
Feature feature = features.get(j);
ContinuousFeature continuousFeature = feature.toContinuousFeature();
Expression expression = continuousFeature.ref();
Double coefficient = pc.apply(j, i);
if(!ValueUtil.isOne(coefficient)){
expression = PMMLUtil.createApply("*", expression, PMMLUtil.createConstant(coefficient));
}
apply.addExpressions(expression);
}
DerivedField derivedField = encoder.createDerivedField(formatName(transformer, i), OpType.CONTINUOUS, DataType.DOUBLE, apply);
result.add(new ContinuousFeature(encoder, derivedField));
}
return result;
}
示例13: toContinuousFeature
import org.dmg.pmml.DerivedField; //导入依赖的package包/类
@Override
public ContinuousFeature toContinuousFeature(){
PMMLEncoder encoder = ensureEncoder();
DerivedField derivedField = encoder.getDerivedField(getName());
if(derivedField == null){
Apply apply = createApply();
derivedField = encoder.createDerivedField(getName(), OpType.CONTINUOUS, getDataType(), apply);
}
return new ContinuousFeature(encoder, derivedField);
}
示例14: getReferencedFieldName
import org.dmg.pmml.DerivedField; //导入依赖的package包/类
private static String getReferencedFieldName(DerivedField derivedField) {
String referencedField = null;
if (derivedField.getExpression() != null) {
if (derivedField.getExpression() instanceof Apply) {
// TODO throw uoe in case the function is not "if missing" - much more to implement!
for (Expression expression : ((Apply) derivedField.getExpression()).getExpressions()) {
if (expression instanceof FieldRef) {
referencedField = ((FieldRef) expression).getField().getValue();
}
}
} else if (derivedField.getExpression() instanceof NormContinuous) {
referencedField = ((NormContinuous) derivedField.getExpression()).getField().getValue();
} else {
throw new UnsupportedOperationException("So far only Apply expression implemented.");
}
} else {
// there is a million ways in which derived fields can reference other fields.
// need to implement them all!
throw new UnsupportedOperationException("So far only implemented if function for derived fields.");
}
if (referencedField == null) {
throw new UnsupportedOperationException("could not find raw field name. Maybe this derived field references another derived " +
"field? Did not implement that yet.");
}
return referencedField;
}
示例15: getAllDerivedFields
import org.dmg.pmml.DerivedField; //导入依赖的package包/类
public static List<DerivedField> getAllDerivedFields(Model model, TransformationDictionary transformationDictionary) {
List<DerivedField> allDerivedFields = new ArrayList<>();
if (transformationDictionary != null) {
allDerivedFields.addAll(transformationDictionary.getDerivedFields());
}
if (model.getLocalTransformations() != null) {
allDerivedFields.addAll(model.getLocalTransformations().getDerivedFields());
}
return allDerivedFields;
}