I have a multi-label classification problem, for which I looked online and saw that for one-hot encoding the labels it is best to use the MultiLabelBinarizer.
I use this for my labels (which i separate from the dataset itself) as follows:
ohe = MultiLabelBinarizer()
labels = ohe.fit_transform(labels)
train, test, train_labels, test_labels = train_test_split(dataset, labels, test_size=0.2) #80% train split
But it throws me this following error:
Traceback (most recent call last):
File "learn.py", line 114, in <module>
train, test, train_labels, test_labels = train_test_split(dataset, labels, test_size=0.2) #80% train split
File "C:\Users\xwb18152\AppData\Roaming\Python\Python38\site-packages\sklearn\model_selection\_split.py", line 2127,
in train_test_split
arrays = indexable(*arrays)
File "C:\Users\xwb18152\AppData\Roaming\Python\Python38\site-packages\sklearn\utils\validation.py", line 293, in indexable
check_consistent_length(*result)
File "C:\Users\xwb18152\AppData\Roaming\Python\Python38\site-packages\sklearn\utils\validation.py", line 256, in check_consistent_length
raise ValueError("Found input variables with inconsistent numbers of"
ValueError: Found input variables with inconsistent numbers of samples: [83292, 5]
--
EDIT: The labels dataset looks as follows (ignore the Interval column, this shouldnt be there and is not actually counted in the rows -- not sure why?):
Movement Distance Speed Delay Loss
Interval
0 1 1 25 0 0
2 1 1 25 0 0
4 1 1 25 0 0
6 1 1 25 0 0
8 1 1 25 0 0
... ... ... ... ... ...
260 3 5 50 0 0
262 3 5 50 0 0
264 3 5 50 0 0
266 3 5 50 0 0
268 3 5 50 0 0
From this we can see that it is a multi-label multi-class classification problem. The shape of the dataset and labels before and after the Binarizer are as follows:
Before After
dataset (83292, 15) (83292, 15)
labels (83292, 5) (5, 18)