1
$\begingroup$

I have a multi-label classification problem where I have more than one target and each of them is a list.

The prediction for each target can be either a list of one or more items (one or more vegetables and one or more fruits)

Features                            lables :  

  A        B       C                Vegetable                fruits
   1       3        8               [carrot, corn, carrot]   [Apricot, Cherry]
   1       3        8               [eggplant, pepper]       [Mango ]
   1       3        8               [carrot]                 [Banana, Cherry, Mango]

I was wondering what is the correct approach to take for example what could be the right model to begin with or is there a predefined models or pre-trinted model for similar problem?

$\endgroup$

2 Answers 2

1
$\begingroup$

If you are considering each recipe a completely different label, despite potential intersection of ingredients, you should encode your targets into distinct classes as you would normally encode labels e.g.:

>>> le = preprocessing.LabelEncoder()
>>> le.fit(["paris", "paris", "tokyo", "amsterdam"])
LabelEncoder()
>>> list(le.classes_)
['amsterdam', 'paris', 'tokyo']
>>> le.transform(["tokyo", "tokyo", "paris"])
array([2, 2, 1]...)
>>> list(le.inverse_transform([2, 2, 1]))
['tokyo', 'tokyo', 'paris']

You have nested lists as class objects so to do the above you could change the type of your label column to string, in something like:

df['str_labels'] = [','.join(map(str, l)) for l in df['list_labels']]
df

   list_labels             str_labels
0  [carrot, corn, carrot]  carrot, corn, carrot
1  [eggplant, pepper]      eggplant, pepper
$\endgroup$
1
$\begingroup$

It is called multi-output, multi-label classification. Multi-output is more than 1 set of targets and within each those separate targets there can be more than 1 label.

One option would be start with traditional machine learning before trying neural networks. Scikit-learn supports this problem formation with MultiOutputClassifier.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.