[SOLVED] Null as a possible result using an IF function

EMDuellEMDuell Member Posts: 21 Contributor II
edited November 2018 in Help
Hello,

This seems basic but I was not able to figure it out, so hoping that someone can help.  

I would like to write a condition like the following:

If(Atrribute="Green",1,NULL)

Where if the matching attribute value is "Green", then the result is yes, but if not, the value is null.  I am using the Generate Attribute operator and attempted to use "" but because the attribute that is generated is a real number, the "" does not work.

Thanks,
Eric

P.S. - Is there a reference of all RapidMiner functions available?  I know there are the built in pop-up windows but those examples are usually very brief and limited (fine for the program, I'm just looking for a reference with more example situations).

Answers

  • JEdwardJEdward RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 578 Unicorn
    There's several ways to do it. This one uses Declare Missing Values to replace some text with the NULL. 
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="5.3.015">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="5.3.015" expanded="true" name="Process">
        <process expanded="true">
          <operator activated="true" class="generate_data_user_specification" compatibility="5.3.015" expanded="true" height="60" name="Generate Data by User Specification" width="90" x="45" y="165">
            <list key="attribute_values">
              <parameter key="Attribute1" value="&quot;Blue&quot;"/>
            </list>
            <list key="set_additional_roles"/>
          </operator>
          <operator activated="true" class="generate_attributes" compatibility="5.3.015" expanded="true" height="76" name="Generate Attributes" width="90" x="112" y="30">
            <list key="function_descriptions">
              <parameter key="Calculation" value="if(Attribute1 == &quot;Green&quot;,1,&quot;I'm a NULL&quot;)"/>
            </list>
          </operator>
          <operator activated="true" class="declare_missing_value" compatibility="5.3.015" expanded="true" height="76" name="Declare Missing Value" width="90" x="246" y="30">
            <parameter key="mode" value="nominal"/>
            <parameter key="nominal_value" value="I'm a NULL"/>
          </operator>
          <connect from_op="Generate Data by User Specification" from_port="output" to_op="Generate Attributes" to_port="example set input"/>
          <connect from_op="Generate Attributes" from_port="example set output" to_op="Declare Missing Value" to_port="example set input"/>
          <connect from_op="Declare Missing Value" from_port="example set output" 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>
  • Marco_BoeckMarco_Boeck Administrator, Moderator, Employee, Member, University Professor Posts: 1,993 RM Engineering
    Hi,

    this would be how you can do it directly with the Generate Attributes operator:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="6.0.004">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="6.0.004" expanded="true" name="Process">
        <process expanded="true">
          <operator activated="true" class="retrieve" compatibility="6.0.004" expanded="true" height="60" name="Retrieve Golf" width="90" x="45" y="30">
            <parameter key="repository_entry" value="//Samples/data/Golf"/>
          </operator>
          <operator activated="true" class="generate_attributes" compatibility="6.0.004" expanded="true" height="76" name="Generate Attributes" width="90" x="179" y="30">
            <list key="function_descriptions">
              <parameter key="attr" value="if(matches(Outlook, &quot;sunny&quot;),1,NaN)"/>
            </list>
          </operator>
          <connect from_op="Retrieve Golf" from_port="output" to_op="Generate Attributes" to_port="example set input"/>
          <connect from_op="Generate Attributes" from_port="example set output" 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>
    Regards,
    Marco
  • EMDuellEMDuell Member Posts: 21 Contributor II
    JEdward, Marco,

    Thanks very much for the replies - I can see situations where both of your suggestions apply.  I appreciate the help!

    -Eric
Sign In or Register to comment.