RapidMiner 9.7 is Now Available

Lots of amazing new improvements including true version control! Learn more about what's new here.

CLICK HERE TO DOWNLOAD

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 Moderator, Member Posts: 1,197   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, Member Posts: 134   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">

    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,926  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
    varunm1jczogalla
  • mschmitzmschmitz Administrator, Moderator, Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert, University Professor Posts: 2,462  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,408   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 Moderator, Member Posts: 1,197   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

    lionelderkrikor
Sign In or Register to comment.