If statement for many value

TiraTira Member Posts: 1 Newbie
I have many type of crime to classify into two group (violence crime and property crime)

I have tried using generate attribute if statement

If(Crime=="murder", "violence crime", "Property crime")

however it gives me an error when i do

If(crime=="murder" ^ "rape" ^ "Crime3", "violence crime", "property crime")

can someone help me?

crime is binominal attribute btw

Answers

  • varunm1varunm1 Member Posts: 661   Unicorn
    Hello @Tira

    Can you try this and see if this works out?

    If(Crime=="murder", "violence crime", If(Crime=="rape", "violence crime", If(Crime=="Crime3", "violence crime", "Property crime")))

    Best
    Varun
  • jczogallajczogalla Employee, Member Posts: 125   RM Engineering
    edited June 12
    Another way to do this would be to have an example set that has to attributes, "crime" and "crime type", where you list for each crime which type it is. Then you can use the Join operator, marking both crime attributes as the key attribute and using a left join (i.e. keep all examples from the original data set). Afterwards, you can use the Replace Missing Values operator on the crime type attribute and specify "property crime" as the replacement.
    <?xml version="1.0" encoding="UTF-8"?><process version="9.3.000">
    <context>
    <input/>
    <output/>
    <macros/>
    </context>
    <operator activated="true" class="process" compatibility="9.3.000" expanded="true" name="Process">
    <parameter key="logverbosity" value="init"/>
    <parameter key="random_seed" value="2001"/>
    <parameter key="send_mail" value="never"/>
    <parameter key="notification_email" value=""/>
    <parameter key="process_duration_for_mail" value="30"/>
    <parameter key="encoding" value="SYSTEM"/>
    <process expanded="true">
    <operator activated="true" class="retrieve" compatibility="9.3.000" expanded="true" height="68" name="Retrieve crime" width="90" x="45" y="85">
    <parameter key="repository_entry" value="//Local Repository/crime"/>
    </operator>
    <operator activated="true" class="retrieve" compatibility="9.3.000" expanded="true" height="68" name="Retrieve crime map" width="90" x="45" y="187">
    <parameter key="repository_entry" value="//Local Repository/crime map"/>
    </operator>
    <operator activated="true" class="concurrency:join" compatibility="9.3.000" expanded="true" height="82" name="Join" width="90" x="246" y="85">
    <parameter key="remove_double_attributes" value="true"/>
    <parameter key="join_type" value="left"/>
    <parameter key="use_id_attribute_as_key" value="false"/>
    <list key="key_attributes">
    <parameter key="crime" value="crime"/>
    </list>
    <parameter key="keep_both_join_attributes" value="false"/>
    </operator>
    <operator activated="true" class="replace_missing_values" compatibility="9.3.000" expanded="true" height="103" name="Replace Missing Values" width="90" x="380" y="85">
    <parameter key="return_preprocessing_model" value="false"/>
    <parameter key="create_view" value="false"/>
    <parameter key="attribute_filter_type" value="single"/>
    <parameter key="attribute" value="crime type"/>
    <parameter key="attributes" value=""/>
    <parameter key="use_except_expression" value="false"/>
    <parameter key="value_type" value="attribute_value"/>
    <parameter key="use_value_type_exception" value="false"/>
    <parameter key="except_value_type" value="time"/>
    <parameter key="block_type" value="attribute_block"/>
    <parameter key="use_block_type_exception" value="false"/>
    <parameter key="except_block_type" value="value_matrix_row_start"/>
    <parameter key="invert_selection" value="false"/>
    <parameter key="include_special_attributes" value="false"/>
    <parameter key="default" value="value"/>
    <list key="columns"/>
    <parameter key="replenishment_value" value="property crime"/>
    </operator>
    <connect from_op="Retrieve crime" from_port="output" to_op="Join" to_port="left"/>
    <connect from_op="Retrieve crime map" from_port="output" to_op="Join" to_port="right"/>
    <connect from_op="Join" from_port="join" to_op="Replace Missing Values" to_port="example set input"/>
    <connect from_op="Replace Missing Values" 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>


    To create this crime mapping example set, you can for example use the Data Editor (found in the View -> Show Panel menu).

    Hope this helps!
    Jan

  • sgenzersgenzer 12Administrator, Moderator, Employee, RapidMiner Certified Analyst, Community Manager, Member, University Professor, PM Moderator Posts: 2,383  Community Manager
    ah there's always many ways to solve these kind of problems! You can also use Generate Attributes and do:

    if(crime=="murder"||crime=="rape"||crime=="Crime3", "violence crime", "property crime")
    Scott
    varunm1jczogalla
  • mschmitzmschmitz Administrator, Moderator, Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert, University Professor Posts: 2,074  RM Data Scientist
    Hi,
    if its getting more complex: I know people using groovy for complex switch case. see: https://medium.com/@mSchmitz_/scripting-in-rapidminer-part-i-macros-b973a298dd8f

    ~Martin

    - Head of Data Science Services at RapidMiner -
    Dortmund, Germany
    jczogalla
  • Telcontar120Telcontar120 Moderator, RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 1,210   Unicorn
    You can also use the Map operator---there are so many ways to do this in RapidMiner!

    Brian T.
    Lindon Ventures 
    Data Science Consulting from Certified RapidMiner Experts
    mschmitzjczogalla
  • varunm1varunm1 Member Posts: 661   Unicorn
    @sgenzer solution is easy, I made complex nested if else. I should stop commenting while writing a paper, looks like the impact is everywhere  ;)
    lionelderkrikor
Sign In or Register to comment.