How to detect attribute type

CharlieFirpoCharlieFirpo Member Posts: 48 Contributor II
edited November 2018 in Help
Dear all!

How can I detect the type of an attribute? I have a Branch operator. If the type of an attribute is numerical then the IF should be run, if the attribute is nominal then the ELSE.

Thank you!!!


  • Options
    CharlieFirpoCharlieFirpo Member Posts: 48 Contributor II
    One way can be use a Numerical to Nominal operator. It works well even if the type of the input attribute is nominal. The RapidMiner functions like 'contains, str, finds...' does not work if the type of one of argument is wrong. And unfortunatelly there is no an 'isnum' function :(

    After the Numerical to Nominal operator one should use a Generate Attribute operator that generates eg. the isNum attribute with this function:
    finds(%{macro_of_attribute_name},"^[0-9]+$") It returns true only if the value of the given attribute consists of only numbers.
    And at the Branch operator the condition type should be 'attribute_value_filter', and the condition value 'isNum=true'.

    It is not difficult but maybe there is a simliest way to do this. Is there?

    Nice day!
  • Options
    lukkilukki Member Posts: 2 Contributor I
    Here my solution:

    I used the "Set Macro"-operator to define a Macro with the name "number" and value "0".
    I used the "Handle Exception"-operator. In the "Catch"-branch I put the "Set Macros"-operatur and give my macro "number" the value "1". In the "Try"-branch I did a "Loop attributes"-operator und used at the option "attribute filter type" the value "value_type" and the option "value type" I gave the value "numeric".
    In the "Loop attributes"-operator I put a "Set macros"-operator and gave my macro "number" the value "2".

    So if my dataset have numeric attributes, the macro "number" have the value "2", if not the macro "number" have the value "1".
Sign In or Register to comment.