本文整理汇总了Java中org.jpmml.evaluator.Evaluator类的典型用法代码示例。如果您正苦于以下问题:Java Evaluator类的具体用法?Java Evaluator怎么用?Java Evaluator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Evaluator类属于org.jpmml.evaluator包,在下文中一共展示了Evaluator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.jpmml.evaluator.Evaluator; //导入依赖的package包/类
@Override
public StructField init(Evaluator evaluator){
OutputField field = getField();
DataType dataType = field.getDataType();
if(dataType == null){
try {
dataType = OutputUtil.getDataType(field.getOutputField(), (ModelEvaluator<?>)evaluator);
this.formatString = false;
} catch(PMMLException pe){
dataType = DataType.STRING;
this.formatString = true;
}
}
return DataTypes.createStructField(getColumnName(), SchemaUtil.translateDataType(dataType), false);
}
示例2: doGetOutputFieldsForPMMLStream
import org.jpmml.evaluator.Evaluator; //导入依赖的package包/类
private List<MLModelField> doGetOutputFieldsForPMMLStream(String pmmlContents) throws SAXException, JAXBException {
List<MLModelField> fieldNames = new ArrayList<>();
PMMLManager pmmlManager = new PMMLManager(IOUtil.unmarshal(new ByteArrayInputStream(pmmlContents.getBytes())));
Evaluator modelEvaluator = (ModelEvaluator<?>) pmmlManager.getModelManager(null, ModelEvaluatorFactory.getInstance());
modelEvaluator.getPredictedFields().forEach((f) -> fieldNames.add(getModelField(modelEvaluator.getDataField(f))));
modelEvaluator.getOutputFields().forEach((f) -> {
OutputField outputField = modelEvaluator.getOutputField(f);
ResultFeatureType resultFeatureType = outputField.getFeature();
if (resultFeatureType != ResultFeatureType.PREDICTED_VALUE &&
resultFeatureType != ResultFeatureType.PREDICTED_DISPLAY_VALUE) {
fieldNames.add(getModelField(outputField));
}
});
return fieldNames;
}
示例3: instantiateJPMMLModel
import org.jpmml.evaluator.Evaluator; //导入依赖的package包/类
private Evaluator instantiateJPMMLModel() {
PMML pmml = null;
try {
pmml = IOUtil.unmarshal(Launcher.class.getResource("/predictionModel-PMML.xml").openStream());
} catch (Exception e) {
e.printStackTrace();
}
PMMLManager pmmlManager = new PMMLManager(pmml);
Evaluator evaluator = (Evaluator) pmmlManager.getModelManager(null, ModelEvaluatorFactory.getInstance());
return evaluator;
}
示例4: doGetOutputFieldsForPMMLStream
import org.jpmml.evaluator.Evaluator; //导入依赖的package包/类
private List<MLModelField> doGetOutputFieldsForPMMLStream(String pmmlContents) throws SAXException, JAXBException, UnsupportedEncodingException {
List<MLModelField> fieldNames = new ArrayList<>();
PMMLManager pmmlManager = new PMMLManager(IOUtil.unmarshal(new ByteArrayInputStream(pmmlContents.getBytes("UTF-8"))));
Evaluator modelEvaluator = (ModelEvaluator<?>) pmmlManager.getModelManager(null, ModelEvaluatorFactory.getInstance());
modelEvaluator.getPredictedFields().forEach((f) -> fieldNames.add(getModelField(modelEvaluator.getDataField(f))));
modelEvaluator.getOutputFields().forEach((f) -> {
OutputField outputField = modelEvaluator.getOutputField(f);
ResultFeatureType resultFeatureType = outputField.getFeature();
if (resultFeatureType != ResultFeatureType.PREDICTED_VALUE &&
resultFeatureType != ResultFeatureType.PREDICTED_DISPLAY_VALUE) {
fieldNames.add(getModelField(outputField));
}
});
return fieldNames;
}
示例5: getInputCols
import org.jpmml.evaluator.Evaluator; //导入依赖的package包/类
public String[] getInputCols() {
Evaluator evaluator = getEvaluator();
List<InputField> inputFields = evaluator.getActiveFields();
Function<InputField, String> function = new Function<InputField, String>() {
@Override
public String apply(InputField inputField) {
return (inputField.getName()).getValue();
}
};
List<String> values = Lists.newArrayList(Lists.transform(inputFields, function));
return values.toArray(new String[values.size()]);
}
示例6: onCreate
import org.jpmml.evaluator.Evaluator; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button loadButton = (Button)findViewById(R.id.loadButton);
View.OnClickListener onClickListener = new View.OnClickListener(){
@Override
public void onClick(View view){
Evaluator evaluator;
try {
evaluator = createEvaluator();
} catch(Exception e){
throw new RuntimeException(e);
}
showEvaluatorDialog(evaluator);
}
};
loadButton.setOnClickListener(onClickListener);
}
示例7: showEvaluatorDialog
import org.jpmml.evaluator.Evaluator; //导入依赖的package包/类
private void showEvaluatorDialog(Evaluator evaluator){
List<FieldName> activeFields = getNames(evaluator.getActiveFields());
List<FieldName> targetFields = getNames(evaluator.getTargetFields());
List<FieldName> outputFields = getNames(evaluator.getOutputFields());
StringBuilder sb = new StringBuilder();
sb.append("Active fields: ").append(activeFields);
sb.append("\n");
sb.append("Target fields: ").append(targetFields);
sb.append("\n");
sb.append("Output fields: ").append(outputFields);
TextView textView = new TextView(this);
textView.setText(sb.toString());
Dialog dialog = new Dialog(this);
dialog.setContentView(textView);
dialog.show();
}
示例8: getInputCols
import org.jpmml.evaluator.Evaluator; //导入依赖的package包/类
public String[] getInputCols(){
Evaluator evaluator = getEvaluator();
List<InputField> inputFields = evaluator.getActiveFields();
Function<InputField, String> function = new Function<InputField, String>(){
@Override
public String apply(InputField inputField){
return (inputField.getName()).getValue();
}
};
List<String> values = Lists.newArrayList(Lists.transform(inputFields, function));
return values.toArray(new String[values.size()]);
}
示例9: loadArguments
import org.jpmml.evaluator.Evaluator; //导入依赖的package包/类
static
private Map<FieldName, FieldValue> loadArguments(Evaluator evaluator, Tuple tuple) throws ExecException {
if(tuple.size() == 1){
byte type = tuple.getType(0);
switch(type){
case DataType.TUPLE:
return loadPrimitiveList(evaluator, (Tuple)tuple.get(0));
default:
break;
}
}
return loadPrimitiveList(evaluator, tuple);
}
示例10: loadPrimitiveList
import org.jpmml.evaluator.Evaluator; //导入依赖的package包/类
static
private Map<FieldName, FieldValue> loadPrimitiveList(Evaluator evaluator, Tuple tuple) throws ExecException {
Map<FieldName, FieldValue> result = Maps.newLinkedHashMap();
List<FieldName> activeFields = evaluator.getActiveFields();
if(activeFields.size() != tuple.size()){
throw new ExecException();
}
int i = 0;
for(FieldName activeField : activeFields){
Object object = tuple.get(i);
FieldValue value = EvaluatorUtil.prepare(evaluator, activeField, object);
result.put(activeField, value);
i++;
}
return result;
}
示例11: storeResult
import org.jpmml.evaluator.Evaluator; //导入依赖的package包/类
static
private Tuple storeResult(Evaluator evaluator, Map<FieldName, ?> result){
List<Object> values = Lists.newArrayList();
List<FieldName> targetFields = evaluator.getTargetFields();
for(FieldName targetField : targetFields){
values.add(EvaluatorUtil.decode(result.get(targetField)));
}
List<FieldName> outputFields = evaluator.getOutputFields();
for(FieldName outputField : outputFields){
values.add(result.get(outputField));
}
TupleFactory tupleFactory = TupleFactory.getInstance();
return tupleFactory.newTuple(values);
}
示例12: evaluateKMeansModel
import org.jpmml.evaluator.Evaluator; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private static void evaluateKMeansModel(Evaluator evaluator){
ClusteringModelEvaluator cluster = (ClusteringModelEvaluator)evaluator;
System.out.println("Cluster centers: ");
Iterator it = cluster.getEntityRegistry().entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry)it.next();
System.out.println(pairs.getKey() + " = " + ((Cluster)pairs.getValue()).getArray().getValue());
}
ClassificationMap map;
map = SparkPMMLExporterValidator.<ClassificationMap>evaluate(new Double[]{5.1,3.5,1.4,0.2}, evaluator);
System.out.println("Cluster assigned to new Double[]{5.1,3.5,1.4,0.2}: " + map.getResult());
map = SparkPMMLExporterValidator.<ClassificationMap>evaluate(new Double[]{5.9,3.0,5.1,1.8}, evaluator);
System.out.println("Cluster assigned to new Double[]{5.9,3.0,5.1,1.8}: " + map.getResult());
}
示例13: initializeArguments
import org.jpmml.evaluator.Evaluator; //导入依赖的package包/类
/**
* @see #initializeSimpleResult(Class)
* @see #initializeComplexResult(Class)
*/
static
public ObjectInspector[] initializeArguments(Class<? extends GenericUDF> clazz, ObjectInspector[] inspectors) throws UDFArgumentException {
Evaluator evaluator = getEvaluator(clazz);
if(inspectors.length == 1){
ObjectInspector inspector = inspectors[0];
ObjectInspector.Category category = inspector.getCategory();
switch(category){
case STRUCT:
return initializeStruct(evaluator, inspector);
default:
return initializePrimitiveList(evaluator, inspectors);
}
}
return initializePrimitiveList(evaluator, inspectors);
}
示例14: loadArguments
import org.jpmml.evaluator.Evaluator; //导入依赖的package包/类
static
private Map<FieldName, FieldValue> loadArguments(Evaluator evaluator, ObjectInspector[] inspectors, GenericUDF.DeferredObject[] objects) throws HiveException {
if(inspectors.length == 1){
ObjectInspector inspector = inspectors[0];
ObjectInspector.Category category = inspector.getCategory();
switch(category){
case STRUCT:
return loadStruct(evaluator, inspectors[0], objects[0]);
default:
return loadPrimitiveList(evaluator, inspectors, objects);
}
}
return loadPrimitiveList(evaluator, inspectors, objects);
}
示例15: storeStruct
import org.jpmml.evaluator.Evaluator; //导入依赖的package包/类
static
private Object[] storeStruct(Evaluator evaluator, Map<FieldName, ?> result){
List<Object> resultStruct = Lists.newArrayList();
List<FieldName> targetFields = evaluator.getTargetFields();
for(FieldName targetField : targetFields){
resultStruct.add(EvaluatorUtil.decode(result.get(targetField)));
}
List<FieldName> outputFields = evaluator.getOutputFields();
for(FieldName outputField : outputFields){
resultStruct.add(result.get(outputField));
}
return resultStruct.toArray(new Object[resultStruct.size()]);
}