Pages: [1]
  Print  
Author Topic: [SOLVED] Null as a possible result using an IF function  (Read 147 times)
EMDuell
Newbie
*
Posts: 5


« on: June 20, 2014, 02:25:08 PM »

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).
« Last Edit: June 23, 2014, 05:38:05 PM by EMDuell » Logged
JEdward
Full Member
***
Posts: 144


« Reply #1 on: June 22, 2014, 05:44:57 AM »

There's several ways to do it. This one uses Declare Missing Values to replace some text with the NULL. 

Code:
<?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>
Logged
Marco Boeck
Administrator
Hero Member
*****
Posts: 879


WWW
« Reply #2 on: June 23, 2014, 07:41:36 AM »

Hi,

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

Code:
<?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
Logged

Join us in Boston for the RapidMiner World conference!

RapidMiner Studio 6 | RapidMiner Studio 6 Q&A
EMDuell
Newbie
*
Posts: 5


« Reply #3 on: June 23, 2014, 05:37:13 PM »

JEdward, Marco,

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

-Eric
Logged
Pages: [1]
  Print  
 
Jump to: