Search code examples
decision-treeknime

Can KNIME create a decision tree based on a set?


I have data that contains sets, for example (this is not my real data):

Name,    Type,     Colors
Pikachu, Electric, Red|Black|Yellow
Raichu,  Electric, Brown
Meowth,  Normal,   Yellow|Brown
Togepi,  Fairy,    Yellow|White|Blue|Red
Eevee,   Normal,   Brown

My goal is to get a rule-set that determines the name based on the type and color.

I'm using Cell Splitter on the last column. I also have Domain Calculator to create discreet values for each column, because some of my columns may have more than 60 values.
Overall, my workflow looks like this:

enter image description here

The data looks OK:

Pikachu Electric    [Red, Black, Yellow]
Raichu  Electric    [Brown]
Meowth  Normal      [Yellow, Brown]
Togepi  Fairy       [Yellow, White, Blue, Red]
Eevee   Normal      [Brown]

My problem is that I can't get the tree to use the Colors set values. My current output rules looks like this - note that the color is not used anywhere:

$Type$ = "Electric" AND TRUE    Pikachu 2.0 1.0
$Type$ = "Normal" AND TRUE      Meowth  2.0 1.0
$Type$ = "Fairy" AND TRUE       Togepi  1.0 1.0

Is it even possible to use a set as part of the decision tree and ruleset? If so, how?


Solution

  • If you add an Ungroup node between the Cell Splitter and Domain Calculator node then I think you get what you want. Using this, and recreating your workflow, I get the following rule set:

    $Colors_SplitResultList$ = "Red" AND $Type$ = "Electric" => "Pikachu"
    $Colors_SplitResultList$ = "Black" AND $Type$ = "Electric" => "Pikachu"
    $Colors_SplitResultList$ = "Yellow" AND $Type$ = "Electric" => "Pikachu"
    $Colors_SplitResultList$ = "Brown" AND $Type$ = "Electric" => "Raichu"
    $Type$ = "Normal" AND TRUE => "Meowth"
    $Type$ = "Fairy" AND TRUE => "Togepi"