Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A mechanism for "showing" implicit attribute values #205

Closed
javide opened this issue Jan 27, 2020 · 6 comments
Closed

A mechanism for "showing" implicit attribute values #205

javide opened this issue Jan 27, 2020 · 6 comments

Comments

@javide
Copy link

javide commented Jan 27, 2020

Hi Villu,

I am using Syncfusion PMML package to make prediction from a model saved by sklearn2pmml and have encountered an issue documented in https://stackoverflow.com/questions/59853972/how-to-make-predictions-with-syncfusion-pmml-from-a-neural-network-trained-with

Syncfusion PMML requires the attribute "feature" to be defined not only in the OutputFields of the output layer, but also in the OutputField of the hidden layer. I wonder whether there is a way to programmatically set this attribute in sklearn2pmml.

Thank you,

Davide

@vruusmann
Copy link
Member

Syncfusion PMML requires the attribute "feature" to be defined not only in the OutputFields of the output layer, but also in the OutputField of the hidden layer.

I'm aiming at compatibility with the PMML specification, not some specific PMML implementation (including my own).

Can you point me to a specific PMML markup/construct that is "interpreted" differently by different parties here? Whoever is wrong (SkLearn2PMML, Syncfusion) should fix their implementation.

I checked the PMML snippet at your SO question, and actually fail to understand what's missing? There is a top-level MiningModel element, which contains two child (aka hidden?) RegressionModel elements. They both have Output/OutputField elements defined.

@vruusmann
Copy link
Member

Workaround: if you're having issues with SkLearn2PMML generated PMML documents, then you might create a small ad hoc Python program that "fixes" the original PMML document in any way you like.

Just wrap the sklearn2pmml function call into some helper function to make everything extra obvious for your data scientsts.

@javide
Copy link
Author

javide commented Jan 27, 2020

As I pointed out to Kavin in a comment to his SO answer, I am under the impression that the issue is on the Syncfusion PMML implementation side. Kavin mentioned that Syncfusion implements http://dmg.org/pmml/v4-4/Output.html#xsdType_RESULT-FEATURE but, as far as I understand from reading the XSD, the feature attribute is not defined as mandatory and a default value is defined instead:

<xs:attribute name="feature" type="RESULT-FEATURE" default="predictedValue"/>

So, I don't think there's anything wrong with the sklearn2pmml library. I was just curious to know whether there was a method to add this attribute. Happy to implement a helper function as you suggested. Thank you.

@vruusmann
Copy link
Member

The OutputField@feature attribute is "optional" in a sense that if left unspecified, it defaults to predictedValue. So the following two PMML fragments should be functionally identical:

Explicit:

<OutputField name="decisionFunction" feature="predictedFeature"/>

Implicit:

<OutputField name="decisionFunction"/>

The SkLearn2PMML package switched from explicit to implicit ~6-9 months ago. There's a special purpose org.jpmml.converter.visitors.AttributeCleaner Visitor class that traverses the in-memory PMML class model object and "suppresses" all default attribute values:
https://github.com/jpmml/jpmml-converter/blob/master/src/main/java/org/jpmml/converter/visitors/AttributeCleaner.java

In a nutshell, you're asking for its inverse - a Visitor class that would make all implicit attributes explicit. This has been requested before by someone else (can't recall exact issue ID, but there was another PMML engine breaking because of this failing explicit/implicit assumption).

TLDR: There might be a use case for implementing such "inverse Visitor class", and making its use configurable via some SkLearn2PMML function flag.

@vruusmann vruusmann changed the title How to programmatically set attribute "feature" in OutputField? A mechanism for "showing" implicit attribute values Jan 27, 2020
@vruusmann
Copy link
Member

vruusmann commented Jan 27, 2020

TLDR: There might be a use case for implementing such "inverse Visitor class", and making its use configurable via some SkLearn2PMML function flag.

Comment out these two lines:
https://github.com/jpmml/jpmml-converter/blob/1.3.10/src/main/java/org/jpmml/converter/ModelEncoder.java#L99-L100

Then, rebuild the JPMML-Converter project, and replace the old JPMML-Converter library JAR file with this new JAR file in sklearn2pmml/resources directory. Now you should have the OutputField@feature attribute showing.

@vruusmann
Copy link
Member

Closing as exact duplicate of jpmml/jpmml-converter#13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants