How to select the highest attribute and write the name into an addi. attr. ?

xDStickerxDSticker Member Posts: 16 Contributor II
edited November 2018 in Help
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?

image

Thank you for your time :)
Sticker

Answers

  • SkirzynskiSkirzynski Member Posts: 164  Maven
    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);&#10;for(Example example : exampleSet) {&#10;&#9;double maxVal = Double.MIN_VALUE;&#10;&#9;Attribute maxAttribute = null;&#10;&#9;for(Attribute attribute : exampleSet.getAttributes()) {&#10;&#9;&#9;if(attribute.getName().equals(&quot;best_confidence_attribute&quot;)) {&#10;&#9;&#9;&#9;continue;&#10;&#9;&#9;}&#10;&#9;&#9;double currentVal = example[attribute.getName()];&#10;&#9;&#9;if(maxVal &lt; currentVal) {&#10;&#9;&#9;&#9;maxVal = currentVal;&#10;&#9;&#9;&#9;maxAttribute = attribute;&#10;&#9;&#9;}&#10;&#9;}&#10;&#9;example['best_confidence_attribute'] = maxAttribute.getName();&#10;}&#10;return exampleSet;&#10;"/>
          </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>
Sign In or Register to comment.