The Altair Community is migrating to a new platform to provide a better experience for you. In preparation for the migration, the Altair Community is on read-only mode from October 28 - November 6, 2024. Technical support via cases will continue to work as is. For any urgent requests from Students/Faculty members, please submit the form linked here

If statement for many value

TiraTira Member Posts: 1 Learner I
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: 1,207 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
    Regards,
    Varun
    https://www.varunmandalapu.com/

    Be Safe. Follow precautions and Maintain Social Distancing

  • jczogallajczogalla Employee-RapidMiner, Member Posts: 144 RM Engineering
    edited June 2019
    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"><br>  <context><br>    <input/><br>    <output/><br>    <macros/><br>  </context><br>  <operator activated="true" class="process" compatibility="9.3.000" expanded="true" name="Process"><br>    <parameter key="logverbosity" value="init"/><br>    <parameter key="random_seed" value="2001"/><br>    <parameter key="send_mail" value="never"/><br>    <parameter key="notification_email" value=""/><br>    <parameter key="process_duration_for_mail" value="30"/><br>    <parameter key="encoding" value="SYSTEM"/><br>    <process expanded="true"><br>      <operator activated="true" class="retrieve" compatibility="9.3.000" expanded="true" height="68" name="Retrieve crime" width="90" x="45" y="85"><br>        <parameter key="repository_entry" value="//Local Repository/crime"/><br>      </operator><br>      <operator activated="true" class="retrieve" compatibility="9.3.000" expanded="true" height="68" name="Retrieve crime map" width="90" x="45" y="187"><br>        <parameter key="repository_entry" value="//Local Repository/crime map"/><br>      </operator><br>      <operator activated="true" class="concurrency:join" compatibility="9.3.000" expanded="true" height="82" name="Join" width="90" x="246" y="85"><br>        <parameter key="remove_double_attributes" value="true"/><br>        <parameter key="join_type" value="left"/><br>        <parameter key="use_id_attribute_as_key" value="false"/><br>        <list key="key_attributes"><br>          <parameter key="crime" value="crime"/><br>        </list><br>        <parameter key="keep_both_join_attributes" value="false"/><br>      </operator><br>      <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"><br>        <parameter key="return_preprocessing_model" value="false"/><br>        <parameter key="create_view" value="false"/><br>        <parameter key="attribute_filter_type" value="single"/><br>        <parameter key="attribute" value="crime type"/><br>        <parameter key="attributes" value=""/><br>        <parameter key="use_except_expression" value="false"/><br>        <parameter key="value_type" value="attribute_value"/><br>        <parameter key="use_value_type_exception" value="false"/><br>        <parameter key="except_value_type" value="time"/><br>        <parameter key="block_type" value="attribute_block"/><br>        <parameter key="use_block_type_exception" value="false"/><br>        <parameter key="except_block_type" value="value_matrix_row_start"/><br>        <parameter key="invert_selection" value="false"/><br>        <parameter key="include_special_attributes" value="false"/><br>        <parameter key="default" value="value"/><br>        <list key="columns"/><br>        <parameter key="replenishment_value" value="property crime"/><br>      </operator><br>      <connect from_op="Retrieve crime" from_port="output" to_op="Join" to_port="left"/><br>      <connect from_op="Retrieve crime map" from_port="output" to_op="Join" to_port="right"/><br>      <connect from_op="Join" from_port="join" to_op="Replace Missing Values" to_port="example set input"/><br>      <connect from_op="Replace Missing Values" from_port="example set output" to_port="result 1"/><br>      <portSpacing port="source_input 1" spacing="0"/><br>      <portSpacing port="sink_result 1" spacing="0"/><br>      <portSpacing port="sink_result 2" spacing="0"/><br>    </process><br>  </operator><br></process><br><br>

    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 Administrator, Moderator, Employee-RapidMiner, RapidMiner Certified Analyst, Community Manager, Member, University Professor, PM Moderator Posts: 2,959 Community Manager
    ah there's always many ways to solve these kind of problems! You can also use Generate Attributes and do:

    crime=="murder"||crime=="rape"||crime=="Crime3", "violence crime", "property crime")if(
    Scott
  • MartinLiebigMartinLiebig Administrator, Moderator, Employee-RapidMiner, RapidMiner Certified Analyst, RapidMiner Certified Expert, University Professor Posts: 3,533 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

    - Sr. Director Data Solutions, Altair RapidMiner -
    Dortmund, Germany
  • Telcontar120Telcontar120 RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 1,635 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
  • varunm1varunm1 Member Posts: 1,207 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  ;)
    Regards,
    Varun
    https://www.varunmandalapu.com/

    Be Safe. Follow precautions and Maintain Social Distancing

Sign In or Register to comment.