"Get and set values using Groovy Script"
Dear All,
I want to learn how to use groovy script.
How to get example values for a particular attribute?
and how to set example values for a particular attribute?
The example by Ingo, pasted below only shows how to iterate over all attributes and all examples.
This is nice, but what if you only want to iterate over all examples of attribute 1,
calculate the sum, and place the result in attribute 2?
How to do this?
Like you start with:
att1 att2
0.1 NaN
0.2 NaN
0.3 NaN
0.4 NaN
And the result will be:
att1 att2
0.1 0.1
0.2 0.3
0.3 0.6
0.4 1.0
Best regards,
Wesesl
ExampleSet exampleSet = operator.getInput(ExampleSet.class);
exampleSet.recalculateAllAttributeStatistics();
for (Attribute attribute : exampleSet.getAttributes()) {
double mean = exampleSet.getStatistics(attribute, Statistics.AVERAGE);
String name = attribute.getName();
for (Example example : exampleSet) {
example[name] = example[name] - mean;
}
}
return exampleSet;
I want to learn how to use groovy script.
How to get example values for a particular attribute?
and how to set example values for a particular attribute?
The example by Ingo, pasted below only shows how to iterate over all attributes and all examples.
This is nice, but what if you only want to iterate over all examples of attribute 1,
calculate the sum, and place the result in attribute 2?
How to do this?
Like you start with:
att1 att2
0.1 NaN
0.2 NaN
0.3 NaN
0.4 NaN
And the result will be:
att1 att2
0.1 0.1
0.2 0.3
0.3 0.6
0.4 1.0
Best regards,
Wesesl
ExampleSet exampleSet = operator.getInput(ExampleSet.class);
exampleSet.recalculateAllAttributeStatistics();
for (Attribute attribute : exampleSet.getAttributes()) {
double mean = exampleSet.getStatistics(attribute, Statistics.AVERAGE);
String name = attribute.getName();
for (Example example : exampleSet) {
example[name] = example[name] - mean;
}
}
return exampleSet;