Options

[SOLVED] Generate Attribute with count of examples

jan87jan87 Member Posts: 14 Contributor II
edited June 2019 in Help
Hello,

I have probably a very simple question:

how can i add an attribute that shows the count of all examples (so the value for this new attribute should always be the same in each row)?

or:

how can i add an attribute that sums up the values of another attribute? I cant use the aggregate operatior because I still need the original attributes...

Thank you very much!

Answers

  • Options
    haddockhaddock Member Posts: 849 Maven
    Hi there,

    Check out macros, which are "global variables" in normal speak, like this...
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="5.2.003">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="5.2.003" expanded="true" name="Process">
        <process expanded="true" height="222" width="820">
          <operator activated="true" class="generate_data" compatibility="5.2.003" expanded="true" height="60" name="Generate Data" width="90" x="61" y="72"/>
          <operator activated="true" class="extract_macro" compatibility="5.2.003" expanded="true" height="60" name="Extract Macro" width="90" x="246" y="75">
            <parameter key="macro" value="exs"/>
          </operator>
          <operator activated="true" class="aggregate" compatibility="5.2.003" expanded="true" height="76" name="Aggregate" width="90" x="385" y="73">
            <list key="aggregation_attributes">
              <parameter key="att1" value="sum"/>
            </list>
          </operator>
          <operator activated="true" class="extract_macro" compatibility="5.2.003" expanded="true" height="60" name="Extract Macro (2)" width="90" x="514" y="30">
            <parameter key="macro" value="sum"/>
            <parameter key="macro_type" value="data_value"/>
            <parameter key="attribute_name" value="sum(att1)"/>
            <parameter key="example_index" value="1"/>
          </operator>
          <operator activated="true" class="generate_attributes" compatibility="5.2.003" expanded="true" height="76" name="Generate Attributes" width="90" x="648" y="120">
            <list key="function_descriptions">
              <parameter key="exs" value="%{exs}"/>
              <parameter key="sum" value="%{sum}"/>
            </list>
          </operator>
          <connect from_op="Generate Data" from_port="output" to_op="Extract Macro" to_port="example set"/>
          <connect from_op="Extract Macro" from_port="example set" to_op="Aggregate" to_port="example set input"/>
          <connect from_op="Aggregate" from_port="example set output" to_op="Extract Macro (2)" to_port="example set"/>
          <connect from_op="Aggregate" from_port="original" to_op="Generate Attributes" to_port="example set input"/>
          <connect from_op="Extract Macro (2)" from_port="example set" to_port="result 1"/>
          <connect from_op="Generate Attributes" from_port="example set output" to_port="result 2"/>
          <portSpacing port="source_input 1" spacing="0"/>
          <portSpacing port="sink_result 1" spacing="0"/>
          <portSpacing port="sink_result 2" spacing="0"/>
          <portSpacing port="sink_result 3" spacing="0"/>
        </process>
      </operator>
    </process>
    Hope that's useful.

  • Options
    jan87jan87 Member Posts: 14 Contributor II
    Thank you, that was very helpful.

    I didnt know that this Extract Macro operator solves exactly this problem.

    Sometimes it is a pity that there is no tutorial for the basic operators (for preprocessing), but the online tutorial covers mostly the modeling operators...
Sign In or Register to comment.