“ValueError: Mix of label input types (string and number)” when using LabelBinarizer

If you do this:

from sklearn import preprocessing
lb = preprocessing.LabelBinarizer()
lb.fit(["a", 2])

You will get the following error:

ValueError: Mix of label input types (string and number)

When you mix numbers and strings, it’s unclear whether you are mixing different types of classes, or if you’re mixing continuous and non-continuous data. If the latter- you don’t want the LabelBinarizer to run on the continuous data, and you should remove it, then re-add to the data later. If the former, you can convert the integers to strings.

Leave a Reply

Your email address will not be published.