Set a classification for certain combinations of different row-values within a group

Hi Community,

I want to search for certain Product-IDs within each Customer-ID. Based on which Product-IDs (only A or only B or the combination of A&B etc.) the customer has bought, the customer should get a certain calssification (Basket-Code).

Example:
image

Could please somebody help me? Are there any nodes made for such classifications?
Thank you!

Best regards
Peter

Hi @peter_b and welcome to the KNIME community forum,

Do you want to label the customers based on if they have bought product A, or B or both?

E.g.:
A&B=> Type-1
A=> Type-2
B=> Type-3

Or

A&B=> Type-1
A=> Type-2
B=> Type-2

Is that right?

You can filter the rows based on these products (optional) and then use a GroupBy node to concatenate the products for each unique customer and finally check the conditions in a Rule Engine node by applying the “? MATCHES ?” function.

Here is an example:
label_customers.knwf (21.1 KB)

Or am I missing something?

:blush:

2 Likes

Hi @armingrudd,
thank you for your fast reply! Yes, that’s alsmost what i need:)

And yes, it should be always a different Type, BUT independent of the order of the letters.
E.g.:
A => Type-1
B => Type-2
A&B => Type-3
B&A => Type-3
etc…

AND: To Add the “Type-X” as a column to the origin table for each Customer-ID, i would use a “Join” node with an inner-join on Customer ID, right?

Thank you!
Peter

Change the expression in the Rule Engine node to this:

$Concatenate(PID)$  MATCHES "(.*a.*)(.*b.*)|(.*b.*)(.*a.*)" => "Type-3"
$Concatenate(PID)$  MATCHES ".*b.*" => "Type-2"
$Concatenate(PID)$  MATCHES ".*a.*" => "Type-1"

Exactly!

:blush:

4 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.