Comments (6)
With the exported pmml file, I want to use jpmml to import it, and form a model with Java.
If you simply want to extract the contents of InlineTable
elements, then you can use the JPMML-Model library for that.
I cast the Object into XercesImpl
You should implement a safe type check using the instanceof
operator. If the object is an instance of org.w3c.dom.Element
, then perform the type cast, and invoke the Element#getTextContent()
method on the resulting object.
You can see how it's done in the JPMML-Evaluator library:
https://github.com/jpmml/jpmml-evaluator/blob/master/pmml-evaluator/src/main/java/org/jpmml/evaluator/InlineTableUtil.java#L77
from jpmml-evaluator.
JPMML-Evaluator provides full support for the TransformationDictionary
element.
I believe that this issue is related to the following StackOverflow thread:
https://stackoverflow.com/questions/42499423/java-to-implement-transformationdictionary-pmml-model
KNIME uses the MapValues
element to represent its Category2Number transformation:
<MapValues outputColumn="out" dataType="integer">
<FieldColumnPair field="LIVE_STS" column="in"/>
<InlineTable>
<row>
<pmml:in>N</pmml:in>
<pmml:out>0</pmml:out>
</row>
<row>
<pmml:in>L</pmml:in>
<pmml:out>1</pmml:out>
</row>
</InlineTable>
</MapValues>
I'm afraid that this is not a valid XML/PMML markup, as the pmml:in
and pmml:out
elements do not specify a namespace declaration. The JPMML-Evaluator gets confused because the input value is supposed to be contained in the in
column, but the InlineTable
element does not contain such column (but there's a pmml:in
column instead).
Can you test if one of the following changes makes JPMML-Evaluator work properly:
- Change the value of
MapValues@outputColumn
attribute topmml:out
, and the value ofFieldColumnPair@column
topmml:in
.
or
- Change the names of
pmml:in
andpmml:out
elements toin
andout
, respectively.
Also, what are your KNIME and JPMML-Evaluator versions? Would hate to waste time on troubleshooting legacy/outdated versions.
from jpmml-evaluator.
For your infos:
I am using:
Knime: 3.2.2
Jpmml-eval: 1.3.4
I saw that knime has released the newer version 3.3.1, and I will try that before I post again, and of course I will try to delete the pmml namespace for a trial.
Merci bien
from jpmml-evaluator.
I tried the Knime 3.3.1, it behaves exactly the same with version 3.2.2 regarding the node Category2Number.
What I expected:
With the exported pmml file, I want to use jpmml to import it, and form a model with Java. Then I would be able to feed the model with a input category, after processing, the model would return a number, the number should be exactly the same as I did get from Knime Category2Number node.
What I did
- I removed the namespace xmlns:pmml="http://www.dmg.org/PMML-4_2"
- I removed all the pmml: ns before the in and out Elements.
Within Java:
PMML pmml = PMMLUtil.unmarshal(new FileInputStream(pmmlPath));
TransformationDictionary td = pmml.getTransformationDictionary();
if(td.hasDerivedFields()) {
List<DerivedField> dfs = td.getDerivedFields();
for(DerivedField df : dfs) {
MapValues mv = (MapValues) df.getExpression();
InlineTable it = mv.getInlineTable();
List<Row> rs = it.getRows();
for(Row r : rs) {
List<Object> os = r.getContent();
for(Object o : os) {
System.out.println(o.toString());
}
}
}
}
Then I checked console output, I got
[in: null]
[out: null]
I cast the Object into XercesImpl
, (I forgot how I got the idea.), and its toString()
method is:
public String toString(){
return "[" + element.getTagName() + " : " + element.getNodeValue + "]";
}
But what I need here is element.getTextValue()
instead of element.getNodeValue
what I want
I want to manually get the in, out text value to form a map to be used for mapping the input category. But I can't get the value. any idea?
Or these above are wrong direction on implement TransformationDictionary
, do you have any other idea?
from jpmml-evaluator.
I removed the namespace xmlns:pmml="http://www.dmg.org/PMML-4_2"
The PMML specification does not define in
and out
elements. So, this KNIME generated PMML document is invalid (because it does not validate against PMML 4.2 XML schema).
You cannot blame valid PMML consumer implementations for not accepting invalid PMML documents.
Let's keep this issue open, and find and document a viable workaround. However, you should definitely file a bug report with KNIME.com, and ask them to fix their software.
from jpmml-evaluator.
I fetched the complete content from InlineTable with
Table<Integer, String, String> t = InlineTableUtil.getContent(it);
thanks, and I will leave this issue open.
As you suggested, I will also try to file a bug report to Knime.
Merci bcp.
from jpmml-evaluator.
Related Issues (20)
- How to work with an association rules model (`AssociationModel` element)? HOT 8
- JPMML is enforcing the definition of target fields while the spec says it is optional HOT 6
- jpmml-evaluator does not handle null values when used in java? HOT 1
- Ability to run multiple JPMML-Evaluator versions in parallel (inside the same JVM) HOT 1
- NumberFormatException for evaluate "Random Survival Forest Model" generated by "SoftwareAG PMML Generator" HOT 3
- Compatibility with GraalVM HOT 12
- Not happy with XGBoost evaluation performance HOT 3
- How to load pre-transpiled PMML service provider JAR files? HOT 2
- Model verification fails for XGBoost models HOT 1
- No class def found for jakarta/xml/bind/JAXBContext HOT 3
- java.lang.IllegalArgumentException: Name cannot be empty HOT 1
- java.lang.NoClassDefFoundError: Could not initialize class org.jpmml.evaluator.FieldUtil HOT 4
- If the version 1.6.4 could work on java 8? HOT 1
- Field pmml(pred) is not defined. HOT 5
- DuplicatedFieldValueException after loading PMML in Java generated by Nyoka HOT 8
- 1.6.4 cannot run on java 8
- Exception: Required attribute `Segmentation@multipleModelMethod` is not defined HOT 3
- Updating Guava dependency to latest HOT 4
- why create jar file create error HOT 1
- LoadingModelEvaluatorBuilder not usable on Android due to "java.lang.NoClassDefFoundError: Failed resolution of: Ljava/awt/Image" HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jpmml-evaluator.