[SOLVED] nested if statements
sukh
New Altair Community Member
HI all,
i need help in solving the problem of rapid miner, As i am formulating some rules using nested if. but getting error message.
my rules are as:
two columns: Dtag and Ttag and the result is saved in result column
Ttag Dtag result Column
present past past
present present present
past past past
past present past
future past past
future present future
if(Ttag== “present”, if(Dtag== “past”, “past”, if(Dtag== “present”, “present” , Dtag)),
if(Ttag== “past”, if(Dtag== “past” , “past” , if(Dtag== “present”, “present” , Dtag)),
if(Ttag== “future” , if(Dtag == “past”, “past”, if(Dtag== “present”, “future”, Dtag))))
Kindly help me.
Thanks and Regards:
Sukh
i need help in solving the problem of rapid miner, As i am formulating some rules using nested if. but getting error message.
my rules are as:
two columns: Dtag and Ttag and the result is saved in result column
Ttag Dtag result Column
present past past
present present present
past past past
past present past
future past past
future present future
if(Ttag== “present”, if(Dtag== “past”, “past”, if(Dtag== “present”, “present” , Dtag)),
if(Ttag== “past”, if(Dtag== “past” , “past” , if(Dtag== “present”, “present” , Dtag)),
if(Ttag== “future” , if(Dtag == “past”, “past”, if(Dtag== “present”, “future”, Dtag))))
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="6.3.000">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="6.3.000" expanded="true" name="Process">
<process expanded="true">
<operator activated="true" class="retrieve" compatibility="6.3.000" expanded="true" height="60" name="Retrieve" width="90" x="45" y="30">
<parameter key="repository_entry" value="//Local Repository/CSVDateTime"/>
</operator>
<operator activated="true" class="generate_attributes" compatibility="6.3.000" expanded="true" height="76" name="Generate Attributes" width="90" x="246" y="30">
<list key="function_descriptions">
<parameter key="AA" value="if(Ttag== “present”, if(Dtag== “past”, “past”, if(Dtag== “present”, “present” , Dtag)), if(Ttag== “past”, if(Dtag== “past” , “past” , if(Dtag== “present”, “present” , Dtag)), if(Ttag== “future” , if(Dtag == “past”, “past”, if(Dtag== “present”, “future”, Dtag))))"/>
</list>
</operator>
<connect from_op="Retrieve" 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>
Kindly help me.
Thanks and Regards:
Sukh
Tagged:
0
Answers
-
Hmm...I don't think that works. I would either use the branch/select sub process operator (setting macros for past, present, future) and then do an if statement in each branch, or use two sets of filter examples in the same way. Either way you will be left with only two choices and can use the if statement, set data, etc...
Scott0 -
Nested If statements can get confusing.
One way to make it easier to calculate them on RapidMiner is to chain them together as the Generate Attributes operator calculates each expression in series.
See this as an example.<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="6.4.000">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="6.4.000" expanded="true" name="Process">
<process expanded="true">
<operator activated="false" class="retrieve" compatibility="6.4.000" expanded="true" height="60" name="Retrieve" width="90" x="45" y="30">
<parameter key="repository_entry" value="//Local Repository/CSVDateTime"/>
</operator>
<operator activated="true" class="subprocess" compatibility="6.4.000" expanded="true" height="76" name="Generate Testing Data" width="90" x="179" y="165">
<process expanded="true">
<operator activated="true" class="text:create_document" compatibility="6.4.001" expanded="true" height="60" name="Create Document" width="90" x="45" y="345">
<parameter key="text" value="Ttag;Dtag;Expected present;present;present present;past;past past;past;past past;present;past future;past;past future;present;future"/>
</operator>
<operator activated="true" class="text:write_document" compatibility="6.4.001" expanded="true" height="76" name="Write Document" width="90" x="112" y="435"/>
<operator activated="true" class="read_csv" compatibility="6.4.000" expanded="true" height="60" name="Read CSV" width="90" x="246" y="480">
<list key="annotations"/>
<list key="data_set_meta_data_information">
<parameter key="0" value="Ttag.true.nominal.attribute"/>
<parameter key="1" value="Dtag.true.nominal.attribute"/>
<parameter key="2" value="ExpectedResult.true.nominal.attribute"/>
</list>
</operator>
<connect from_op="Create Document" from_port="output" to_op="Write Document" to_port="document"/>
<connect from_op="Write Document" from_port="file" to_op="Read CSV" to_port="file"/>
<connect from_op="Read CSV" from_port="output" to_port="out 1"/>
<portSpacing port="source_in 1" spacing="0"/>
<portSpacing port="sink_out 1" spacing="0"/>
<portSpacing port="sink_out 2" spacing="0"/>
</process>
</operator>
<operator activated="true" class="generate_attributes" compatibility="6.4.000" expanded="true" height="76" name="Generate Attributes" width="90" x="447" y="120">
<list key="function_descriptions">
<parameter key="AA" value="if(((Ttag == "present") && (Dtag == "present")),"present","TBC")"/>
<parameter key="AA" value="if(((Ttag == "present") && (Dtag == "past") && (AA == "TBC")),"past",AA)"/>
<parameter key="AA" value="if(((Ttag == "past") && (Dtag == "past") && (AA == "TBC")),"past",AA)"/>
<parameter key="AA" value="if(((Ttag == "past") && (Dtag == "present") && (AA == "TBC")),"past",AA)"/>
<parameter key="AA" value="if(((Ttag == "future") && (Dtag == "past") && (AA == "TBC")),"past",AA)"/>
<parameter key="AA" value="if(((Ttag == "future") && (Dtag == "present") && (AA == "TBC")),"future",AA)"/>
</list>
<description align="center" color="transparent" colored="false" width="126">Generate Attributes executes each calulation in series so you can chain them together.</description>
</operator>
<connect from_op="Generate Testing Data" from_port="out 1" 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>0 -
Hi,
you can use nested if functions without problems, however when using such highly nested ones, you must absolutely make sure each function consists of the 3 different parts: The condition, the result for condition = true and the result for condition = false.
Your expression does not do that, you have multiple if expressions left which do not consist of these 3 parts.
if (condition, valueForTrue, valueForFalse)
Simple example:
Regards,
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="6.5.000-SNAPSHOT">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="6.0.002" expanded="true" name="Process">
<process expanded="true">
<operator activated="true" class="retrieve" compatibility="6.5.000-SNAPSHOT" 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.5.000-SNAPSHOT" expanded="true" height="76" name="Generate Attributes" width="90" x="179" y="30">
<list key="function_descriptions">
<parameter key="Temperature_Nominal" value="if (Temperature<=75, "cool", if (Temperature>=85, "hot", "medium"))"/>
</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>
Marco0 -
Dear All,
I have tried using generate attribute with series of expressions, it worked accordingly.
Thanks alot.
Regards:
Sukh0