本文整理汇总了Java中org.jpmml.evaluator.ModelEvaluator类的典型用法代码示例。如果您正苦于以下问题:Java ModelEvaluator类的具体用法?Java ModelEvaluator怎么用?Java ModelEvaluator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ModelEvaluator类属于org.jpmml.evaluator包,在下文中一共展示了ModelEvaluator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newModelEvaluator
import org.jpmml.evaluator.ModelEvaluator; //导入依赖的package包/类
@Override
public ModelEvaluator<? extends Model> newModelEvaluator(PMML pmml, Model model){
ModelEvaluator<?> modelEvaluator = super.newModelEvaluator(pmml, model);
if(modelEvaluator instanceof MiningModelEvaluator){
this.miningModelCount++;
} else
if(modelEvaluator instanceof TreeModelEvaluator){
this.treeModelCount++;
} else
{
throw new AssertionError();
}
return modelEvaluator;
}
示例2: init
import org.jpmml.evaluator.ModelEvaluator; //导入依赖的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);
}
示例3: doGetOutputFieldsForPMMLStream
import org.jpmml.evaluator.ModelEvaluator; //导入依赖的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;
}
示例4: doGetOutputFieldsForPMMLStream
import org.jpmml.evaluator.ModelEvaluator; //导入依赖的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: SegmentHandler
import org.jpmml.evaluator.ModelEvaluator; //导入依赖的package包/类
private SegmentHandler(ModelEvaluator<?> modelEvaluator){
setModelEvaluator(modelEvaluator);
boolean compatible = true;
List<InputField> inputFields = modelEvaluator.getInputFields();
for(InputField inputField : inputFields){
Field field = inputField.getField();
if(field instanceof DataField){
MiningField miningField = inputField.getMiningField();
compatible &= MiningFieldUtil.isDefault(miningField);
}
}
setCompatible(compatible);
}
示例6: evaluate
import org.jpmml.evaluator.ModelEvaluator; //导入依赖的package包/类
@Test
public void evaluate() throws Exception {
ModelEvaluator<?> evaluator = createModelEvaluator();
Map<FieldName, ?> arguments = createArguments("Integer", null, "Double", 76.45d);
Map<FieldName, ?> result = evaluator.evaluate(arguments);
NodeScoreDistribution<?> targetValue = (NodeScoreDistribution<?>)result.get(evaluator.getTargetFieldName());
assertEquals("Result1", targetValue.getResult());
assertEquals("10", targetValue.getEntityId());
assertEquals(21d / 42d, targetValue.getProbability("Result1"), 1e-8);
assertEquals(15d / 42d, targetValue.getProbability("Result2"), 1e-8);
assertEquals(6d / 42d, targetValue.getProbability("Result3"), 1e-8);
}
示例7: evaluate
import org.jpmml.evaluator.ModelEvaluator; //导入依赖的package包/类
@Test
public void evaluate() throws Exception {
ModelEvaluator<?> evaluator = createModelEvaluator();
Map<FieldName, ?> arguments = createArguments("item", Arrays.asList("Cracker", "Coke"));
Map<FieldName, ?> result = evaluator.evaluate(arguments);
assertEquals("1", getOutput(result, "entityId"));
checkValue(Arrays.asList("Cracker"), result, "antecedent");
checkValue(Arrays.asList("Water"), result, "consequent");
checkValue("{Cracker}->{Water}", result, "rule");
checkValue("1", result, "ruleId");
checkValue(1d, result, "support");
checkValue(1d, result, "confidence");
checkValue(1d, result, "lift");
}
示例8: evaluate
import org.jpmml.evaluator.ModelEvaluator; //导入依赖的package包/类
@Test
public void evaluate() throws Exception {
ModelEvaluator<?> evaluator = createModelEvaluator();
Map<FieldName, ?> arguments = createArguments("input", 4d);
Map<FieldName, ?> result = evaluator.evaluate(arguments);
assertEquals(8d, getTarget(result, "result"));
assertEquals(8d, getOutput(result, "RawResult"));
assertEquals(8, getOutput(result, "RawIntegerResult"));
assertEquals(35d, getOutput(result, "FinalResult"));
assertEquals(35, getOutput(result, "FinalIntegerResult"));
assertEquals("waive", getOutput(result, "BusinessDecision"));
}
示例9: load
import org.jpmml.evaluator.ModelEvaluator; //导入依赖的package包/类
@SuppressWarnings (
value = {"resource"}
)
public Model load(InputStream is) throws Exception {
CountingInputStream countingIs = new CountingInputStream(is);
HashingInputStream hashingIs = new HashingInputStream(Hashing.md5(), countingIs);
ModelEvaluator<?> evaluator = unmarshal(hashingIs, this.validate);
PMML pmml = evaluator.getPMML();
for(Class<? extends Visitor> visitorClazz : this.visitorClazzes){
Visitor visitor = visitorClazz.newInstance();
visitor.applyTo(pmml);
}
evaluator.verify();
Model model = new Model(evaluator);
model.putProperty(Model.PROPERTY_FILE_SIZE, countingIs.getCount());
model.putProperty(Model.PROPERTY_FILE_MD5SUM, (hashingIs.hash()).toString());
return model;
}
示例10: createEvaluator
import org.jpmml.evaluator.ModelEvaluator; //导入依赖的package包/类
static
public Evaluator createEvaluator(InputStream is) throws SAXException, JAXBException {
Source source = ImportFilter.apply(new InputSource(is));
PMML pmml = JAXBUtil.unmarshalPMML(source);
// If the SAX Locator information is available, then transform it to java.io.Serializable representation
LocatorTransformer locatorTransformer = new LocatorTransformer();
locatorTransformer.applyTo(pmml);
ModelEvaluatorFactory modelEvaluatorFactory = ModelEvaluatorFactory.newInstance();
ModelEvaluator<?> modelEvaluator = modelEvaluatorFactory.newModelManager(pmml);
modelEvaluator.verify();
return modelEvaluator;
}
示例11: createEvaluator
import org.jpmml.evaluator.ModelEvaluator; //导入依赖的package包/类
static
public Evaluator createEvaluator(InputStream is) throws Exception {
PMML pmml = SerializationUtil.deserializePMML(is);
ModelEvaluatorFactory modelEvaluatorFactory = ModelEvaluatorFactory.newInstance();
ModelEvaluator<?> modelEvaluator = modelEvaluatorFactory.newModelEvaluator(pmml);
modelEvaluator.verify();
return modelEvaluator;
}
示例12: doGetInputFieldsFromPMMLStream
import org.jpmml.evaluator.ModelEvaluator; //导入依赖的package包/类
private List<MLModelField> doGetInputFieldsFromPMMLStream(String pmmlContents) throws SAXException, JAXBException {
final List<MLModelField> fieldNames = new ArrayList<>();
PMMLManager pmmlManager = new PMMLManager(IOUtil.unmarshal(new ByteArrayInputStream(pmmlContents.getBytes())));
Evaluator modelEvaluator = (ModelEvaluator<?>) pmmlManager.getModelManager(null, ModelEvaluatorFactory.getInstance());
for (FieldName predictedField : modelEvaluator.getActiveFields()) {
fieldNames.add(getModelField(modelEvaluator.getDataField(predictedField)));
}
return fieldNames;
}
示例13: doGetInputFieldsFromPMMLStream
import org.jpmml.evaluator.ModelEvaluator; //导入依赖的package包/类
private List<MLModelField> doGetInputFieldsFromPMMLStream(String pmmlContents) throws SAXException, JAXBException, UnsupportedEncodingException {
final 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());
for (FieldName predictedField: modelEvaluator.getActiveFields()) {
fieldNames.add(getModelField(modelEvaluator.getDataField(predictedField)));
}
return fieldNames;
}
示例14: createNestedOutputFields
import org.jpmml.evaluator.ModelEvaluator; //导入依赖的package包/类
private List<OutputField> createNestedOutputFields(List<Segment> segments){
List<OutputField> result = new ArrayList<>();
BiMap<String, Segment> entityRegistry = getEntityRegistry();
for(int i = 0, max = segments.size(); i < max; i++){
Segment segment = segments.get(i);
Model model = segment.getModel();
if(model == null){
throw new MissingElementException(MissingElementException.formatMessage(XPathUtil.formatElement(segment.getClass()) + "/<Model>"), segment);
}
String segmentId = EntityUtil.getId(segment, entityRegistry);
SegmentHandler segmentHandler = this.segmentHandlers.get(segmentId);
if(segmentHandler == null){
segmentHandler = createSegmentHandler(model);
this.segmentHandlers.putIfAbsent(segmentId, segmentHandler);
}
ModelEvaluator<?> modelEvaluator = segmentHandler.getModelEvaluator();
List<OutputField> outputFields = modelEvaluator.getOutputFields();
for(OutputField outputField : outputFields){
OutputField nestedOutputField = new OutputField(outputField);
result.add(nestedOutputField);
}
}
return ImmutableList.copyOf(result);
}
示例15: createSegmentHandler
import org.jpmml.evaluator.ModelEvaluator; //导入依赖的package包/类
private SegmentHandler createSegmentHandler(Model model){
ModelEvaluatorFactory modelEvaluatorFactory = getModelEvaluatorFactory();
if(modelEvaluatorFactory == null){
modelEvaluatorFactory = ModelEvaluatorFactory.newInstance();
}
ModelEvaluator<?> modelEvaluator = modelEvaluatorFactory.newModelEvaluator(getPMML(), model);
return new SegmentHandler(modelEvaluator);
}