|
@@ -1,6 +1,8 @@
|
|
-import org.dmg.pmml.FieldName;
|
|
|
|
import org.jpmml.evaluator.*;
|
|
import org.jpmml.evaluator.*;
|
|
|
|
+import org.jpmml.evaluator.visitors.DefaultModelEvaluatorBattery;
|
|
|
|
+import org.jpmml.model.visitors.VisitorBattery;
|
|
import org.xml.sax.SAXException;
|
|
import org.xml.sax.SAXException;
|
|
|
|
+import org.dmg.pmml.FieldName;
|
|
|
|
|
|
import javax.xml.bind.JAXBException;
|
|
import javax.xml.bind.JAXBException;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
@@ -13,9 +15,12 @@ public class Server {
|
|
|
|
|
|
public static void main(String[] args) throws JAXBException, SAXException, IOException {
|
|
public static void main(String[] args) throws JAXBException, SAXException, IOException {
|
|
// Building a model evaluator from a PMML file
|
|
// Building a model evaluator from a PMML file
|
|
- String modelPath = "lgb_model.pmml";
|
|
|
|
- System.out.println(modelPath);
|
|
|
|
- Evaluator evaluator = new LoadingModelEvaluatorBuilder().load(new File(modelPath)).build();
|
|
|
|
|
|
+ String modelPath = "/Users/alvin/Downloads/first_test.pmml";
|
|
|
|
+ //String modelPath = "lgb_model.pmml";
|
|
|
|
+ //System.out.println(modelPath);
|
|
|
|
+ Evaluator evaluator = new LoadingModelEvaluatorBuilder()
|
|
|
|
+ .setLocatable(false)
|
|
|
|
+ .load(new File(modelPath)).build();
|
|
|
|
|
|
// Performing the self-check
|
|
// Performing the self-check
|
|
evaluator.verify();
|
|
evaluator.verify();
|
|
@@ -38,37 +43,38 @@ public class Server {
|
|
System.out.println(outputField);
|
|
System.out.println(outputField);
|
|
}
|
|
}
|
|
|
|
|
|
- // Predicting
|
|
|
|
- Map<String, Double> inputRecord = new LinkedHashMap<String, Double>();
|
|
|
|
- // 5.1, 3.5, 1.4, 0.2 -> 0
|
|
|
|
- // 6.4, 3.2, 4.5, 1.5 -> 1
|
|
|
|
- // 5.9, 3. , 5.1, 1.8 -> 2
|
|
|
|
- inputRecord.put("sepal_length_(cm)", 5.1);
|
|
|
|
- inputRecord.put("sepal_width_(cm)", 3.5);
|
|
|
|
- inputRecord.put("petal_length_(cm)", 1.4);
|
|
|
|
- inputRecord.put("petal_width_(cm)", 0.2);
|
|
|
|
-
|
|
|
|
- Map<FieldName, FieldValue> arguments = new LinkedHashMap<FieldName, FieldValue>();
|
|
|
|
-
|
|
|
|
- // Mapping the record field-by-field from data source schema to PMML schema
|
|
|
|
- for (InputField inputField : inputFields) {
|
|
|
|
- FieldName inputName = inputField.getName();
|
|
|
|
-
|
|
|
|
- Object rawValue = inputRecord.get(inputName.getValue());
|
|
|
|
-
|
|
|
|
- // Transforming an arbitrary user-supplied value to a known-good PMML value
|
|
|
|
- FieldValue inputValue = inputField.prepare(rawValue);
|
|
|
|
-
|
|
|
|
- arguments.put(inputName, inputValue);
|
|
|
|
|
|
+ List<String> strings = FileUtil.readToLines("/Users/alvin/Downloads/11111111111111111111111111111111111111.csv");
|
|
|
|
+ for (String string : strings) {
|
|
|
|
+ // Predicting
|
|
|
|
+ Float[] doubles = new Float[23];
|
|
|
|
+ String[] split = string.split(",");
|
|
|
|
+ for (int i = 0; i < split.length; i++) {
|
|
|
|
+ if (split[i].length() == 0) {
|
|
|
|
+ doubles[i] = new Float(0);
|
|
|
|
+ } else {
|
|
|
|
+ doubles[i] = new Float(split[i]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Float[] arr = new Float[]{5.1f, 3.5f, 1.4f, 0.2f};
|
|
|
|
+
|
|
|
|
+ Map<FieldName, FieldValue> arguments = new LinkedHashMap<FieldName, FieldValue>();
|
|
|
|
+
|
|
|
|
+ // Mapping the record field-by-field from data source schema to PMML schema
|
|
|
|
+ for (int i = 0; i < inputFields.size(); i++) {
|
|
|
|
+ InputField inputField = inputFields.get(i);
|
|
|
|
+ arguments.put(inputField.getName(), inputField.prepare(doubles[i]));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Evaluating the model with known-good arguments
|
|
|
|
+ Map<FieldName, ?> results = evaluator.evaluate(arguments);
|
|
|
|
+ //System.out.println(results);
|
|
|
|
+
|
|
|
|
+ // Decoupling results from the JPMML-Evaluator runtime environment
|
|
|
|
+ Map<String, ?> resultRecord = EvaluatorUtil.decodeAll(results);
|
|
|
|
+ System.out.println(resultRecord);
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
|
|
|
|
- // Evaluating the model with known-good arguments
|
|
|
|
- Map<FieldName, ?> results = evaluator.evaluate(arguments);
|
|
|
|
- System.out.println(results);
|
|
|
|
-
|
|
|
|
- // Decoupling results from the JPMML-Evaluator runtime environment
|
|
|
|
- Map<String, ?> resultRecord = EvaluatorUtil.decodeAll(results);
|
|
|
|
- System.out.println(resultRecord);
|
|
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|