[scikit-learn] MultiBinarizer issue

Andreas Mueller t3kcit at gmail.com
Wed Sep 18 11:16:44 EDT 2019


Please don't repost questions.
Also, you didn't create a minimal reproducible example as suggested on 
stackoverflow:
https://stackoverflow.com/help/minimal-reproducible-example

That process would probably have shown you where the issue is.
I highly recommend doing that next time.


On 9/16/19 12:12 AM, Sayak Paul wrote:
>
> I am working on a multi-label text classification problem. In order to 
> encode the labels, I am using |MultiLabelBinarizer|. The labels of the 
> dataset look like -
>
> |[cs.AI,cs.CL,cs.CV,cs.NE,stat.ML][cs.CL,cs.AI,cs.LG,cs.NE,stat.ML][cs.CL,cs.AI,cs.LG,cs.NE,stat.ML][stat.ML,cs.AI,cs.CL,cs.LG,cs.NE][cs.CL,cs.AI,cs.LG,cs.NE,stat.ML]|
>
> When I am using
>
> |mlb =MultiLabelBinarizer()mlb.fit(labels)print(mlb.classes_)|
>
> It gives me -
>
> |array([' 
> ',',','.','A','B','C','D','E','G','H','I','L','M','N','O','P','R','S','T','V','Y','[',']','a','c','h','m','s','t'],dtype=object)|
>
> I (partially) fixed this problem by |mlb.fit([y_train])| and I got (I 
> printed first 10 classes) -
>
> |array(['[cs.AI, cs.CC]','[cs.AI, cs.CV]','[cs.AI, cs.CY]','[cs.AI, 
> cs.DB]','[cs.AI, cs.DS]','[cs.AI, cs.GT]','[cs.AI, cs.HC]','[cs.AI, 
> cs.IR]','[cs.AI, cs.LG, stat.ML]','[cs.AI, cs.LG]'],dtype=object)|
>
> Ideally, it should output the individual classes (there may be 
> something wrong in my code). When I am using 
> |mlb.fit_transform([y_train])|, I am getting -
>
> |array([[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]])|
>
> Help would be very much appreciated.
>
> Here's the corresponding StackOverflow issue: 
> https://stackoverflow.com/questions/57917936/multilabelbinarizer-gives-individual-characters-instead-of-the-classes
>
>
> Sayak Paul |sayak.dev <http://sayak.dev>
>
> _______________________________________________
> scikit-learn mailing list
> scikit-learn at python.org
> https://mail.python.org/mailman/listinfo/scikit-learn

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-learn/attachments/20190918/71b23522/attachment-0001.html>


More information about the scikit-learn mailing list