-
Notifications
You must be signed in to change notification settings - Fork 256
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
How to work with an association rules model (AssociationModel
element)?
#250
Comments
The JPMML-Example project was last updated in October 2013, which is more than nine years ago. You can't realistically expect this code to work without changes. This project has been marked as "(public) Archived".
The The idea behind this change is to keep input field validation "local and well encapsulated". You can take an
This should become: FieldValue preparedValue = activeField.prepare(Arrays.asList("Bakery", "Milk")); Please note that if the input field expects a collection-type value, then it should be passed a |
Anyway, keeping this issue open as a reminder to write a small blog post about working with association models. Association models are different from ordinary supervised learning models (eg. classification, regression), as well as from ordinary unsupervised learning models (eg. clustering). They match pretty nicely with JPMML-Evaluator API conventions, but there are some gotchas. |
Thanks for the direction. FieldValue activeValue = activeField.prepare(Arrays.asList("Bakery", "Milk")); // as per suggested changes
// Making arguments
Map<InputField, FieldValue> arguments = Collections.singletonMap(activeField, activeValue);
// From here, I can't proceed forward
Map<FieldName, ?> result = associationModelEvaluator.evaluate(arguments); The very last line errors: "Required Map<String, ?> received Map<InputField, FieldValue>". I had to make arguments object Will that be possible to have some more code so that I can make it clear how the predictions (or recommendations) are made? How the In your own time, |
If you get stuck with compiler errors (when dealing with such high-level APIs such as The main API change between JPMML-Evaluator 1.5.X and 1.6.X is that now all Map keys are field names as Therefore, the correct code snip for you would be: Map<String, ?> arguments = Collections.singletonMap(activeField.getName(), activeValue); |
That will be explained in the upcoming blog post. Unfortunately, the timeline for it is unclear (could be days, could be weeks or even months away).
The target value is model type-specific. For the association rules model type (the As you can see, the "public API surface" of this class is defined by Cast your target value into those interface types, and collect whatever prediction details you need: Map<String, ?> results = associationModelEvaluator.evaluate(arguments);
// Association rules model is "unsupervised" in a sense that it doesn't provide a target field definition.
// The target value is mapped to the `null` key in such a case
Object targetValue = results.get(null);
org.jpmml.evaluator.HasRuleValues association = (org.jpmml.evaluator.HasRuleValues)targetValue;
List<AssociationRule> recommendations = association.getRuleValues(OutputField.Algorithm.RECOMMENDATION);
System.out.println(recommendations);
Available as |
AssociationModel
element)?
Hello VR, To give you the context, here's the code: // The path to pmml (this is the example file from official site given as link below this snippet)
String path = "AssociationModel.pmml";
File initialFile = new File(path);
InputStream targetStream = new FileInputStream(initialFile);
PMML pmml = PMMLUtil.unmarshal(targetStream);
AssociationModelEvaluator associationModelEvaluator = new AssociationModelEvaluator(pmml);
List<InputField> activeFields = associationModelEvaluator.getActiveFields();
// The Association rules model must contain exactly one MiningField whose type is "active"
if(activeFields.size() != 1){
System.out.println("More mining fields found: " + activeFields.size());
throw new IllegalArgumentException();
}
InputField activeField = activeFields.get(0);
// Make sure that all user supplied item values conform to the data schema
FieldValue activeValue = activeField.prepare(Arrays.asList("Cracker", "Coke"));
Map<String, ?> arguments = Collections.singletonMap(activeField.getName(), activeValue);
Map<String, ?> result = associationModelEvaluator.evaluate(arguments); The last line of code throws:
I am using jpmml-evaluator version 1.6.3. Now obviously I am getting something wrong and apologies to ask it, because as you've said about writing a small blog on it, I am not sure how to proceed with Associations without a blog's guidance and example. Since Association models are very different from the other models, I am even unsure whether As you've mentioned in issue#9 about what can we "expect" (3 expectations) from an association file rather than generic Supervised models (to make predictions), I am willing to get the recommendations based on the given item. I know, I am more or less asking to write a thorough example, but if possible can you provide some snippet so that I can proceed ahead? Thank you. |
Pay attention to the type of the exception being thrown - it is plain This exception signals that the model evaluator object is currently in improper state (there's some configuration information missing), and therefore cannot be used for prediction. The root cause for this is that you have constructed a model evaluator object by directly invoking the
Your PMML model has two input fields - one so-called group field ("transaction") and one active field ("item"). You should pay attention to both of them. Therefore, replace |
Handling group fields: The This CSV file should have two data columns - one for transaction identifiers (labelled "transaction") and another one for grocery items (labelled "item"). |
I am trying to run the Association model in my workflow referring to this example: Example Link
I am using jpmml-evaluator version 1.6.3 and it seems like the EvaluatorUtil class no longer have a .prepare method as shown in the example: Example link 54th line
My code goes like:
My IDE shows an error under EvaluatorUtil.prepare(...).
I would really appreciate your help Villu sir.
Thank you.
The text was updated successfully, but these errors were encountered: