简体   繁体   中英

2D matrix for labelbinarizer

There is one behavior of labelbinarizer

import numpy as np
from sklearn import preprocessing
lb = preprocessing.LabelBinarizer()
lb.fit(np.array([[0, 1, 1], [1, 0, 0]]))
lb.classes_

The output is array([0, 1, 2]) . Why there is a 2 there?

Because you have passed a 2-d label-indicator matrix.

A label indicator matrix is mostly used in multi-label problems where more than one labels can be present for a sample. So how do we represent them:

           class 1     class 2     class 3
sample1      0           1            1
sample2      1           0            0
sample3
...

0 means the label is not present and 1 means thats present. So for your current supplied matrix how many classes are there? -- 3

So they are represented using 0,1,2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM