How to select the highest attribute and write the name into an addi. attr. ?
xDSticker
New Altair Community Member
Hi all Data Miners
I just woundering how to select the best (highest) confidence and write it into a extra attribute.
For example: I have calculated the confidences for 4 products, to be a member of an cluster. Everything is well done, but how can i write the attributename with the highest value into a additional attribute?
Thank you for your time
Sticker
I just woundering how to select the best (highest) confidence and write it into a extra attribute.
For example: I have calculated the confidences for 4 products, to be a member of an cluster. Everything is well done, but how can i write the attributename with the highest value into a additional attribute?
Thank you for your time
Sticker
Tagged:
0
Answers
-
Hey,
To be honest: This sounds easier than it actually is. I have tried several approaches, but couldn't find a satisfying solution (which does not mean there is none). In such cases you can use the "Execute Script" operator, which is not recommended, but it works. See the attached process. If I come up with a better solution I will post it here again.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="5.3.009">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="5.3.009" expanded="true" name="Process">
<process expanded="true">
<operator activated="true" class="generate_data" compatibility="5.3.009" expanded="true" height="60" name="Generate Data" width="90" x="45" y="30">
<parameter key="number_examples" value="10"/>
<parameter key="number_of_attributes" value="10"/>
<parameter key="attributes_lower_bound" value="0.0"/>
</operator>
<operator activated="true" class="generate_empty_attribute" compatibility="5.3.009" expanded="true" height="76" name="Generate Empty Attribute" width="90" x="179" y="30">
<parameter key="name" value="best_confidence_attribute"/>
<parameter key="value_type" value="polynominal"/>
</operator>
<operator activated="true" class="execute_script" compatibility="5.3.009" expanded="true" height="76" name="Execute Script" width="90" x="313" y="30">
<parameter key="script" value="ExampleSet exampleSet = operator.getInput(ExampleSet.class); for(Example example : exampleSet) { 	double maxVal = Double.MIN_VALUE; 	Attribute maxAttribute = null; 	for(Attribute attribute : exampleSet.getAttributes()) { 		if(attribute.getName().equals("best_confidence_attribute")) { 			continue; 		} 		double currentVal = example[attribute.getName()]; 		if(maxVal < currentVal) { 			maxVal = currentVal; 			maxAttribute = attribute; 		} 	} 	example['best_confidence_attribute'] = maxAttribute.getName(); } return exampleSet; "/>
</operator>
<connect from_op="Generate Data" from_port="output" to_op="Generate Empty Attribute" to_port="example set input"/>
<connect from_op="Generate Empty Attribute" from_port="example set output" to_op="Execute Script" to_port="input 1"/>
<connect from_op="Execute Script" from_port="output 1" to_port="result 1"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_result 1" spacing="0"/>
<portSpacing port="sink_result 2" spacing="0"/>
</process>
</operator>
</process>0