13 Security Lab

Error: preprocessing.LabelEncoder() - fit() - transform() "TypeError: unorderable types: NoneType() < NoneType()" 본문

Computer Science/Programming

Error: preprocessing.LabelEncoder() - fit() - transform() "TypeError: unorderable types: NoneType() < NoneType()"

Maj0r Tom 2018. 5. 14. 23:18

Error problem
from  >> preprocessing.LabelEncoder() - fit() - transform()

Message is "TypeError: unorderable types: NoneType() < NoneType()" 

 

Problem Definition

ERR code line

1
2
3
le_1 = preprocessing.LabelEncoder() 
training_tr_le = le_1.fit(training_labels) 
training_labels_encoded = training_le.transform(training_labels)

 

 

Error Message

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-19-108d8c779432> in <module>()
     12                        names=['File''Class'])
     13 val_images, val_labels, val_files = load_validation_images(VAL_IMAGES_DIR, val_data)
---> 14 val_labels_encoded = training_le.transform(val_labels)
     15 print(val_labels_encoded[0:30])
 
~/.conda/envs/python35/lib/python3.5/site-packages/sklearn/preprocessing/label.py in transform(self, y)
    128         y = column_or_1d(y, warn=True)
    129 
--> 130         classes = np.unique(y)
    131         if len(np.intersect1d(classes, self.classes_)) < len(classes):
    132             diff = np.setdiff1d(classes, self.classes_)
 
~/.conda/envs/python35/lib/python3.5/site-packages/numpy/lib/arraysetops.py in unique(ar, return_index, return_inverse, return_counts, axis)
    208     ar = np.asanyarray(ar)
    209     if axis is None:
--> 210         return _unique1d(ar, return_index, return_inverse, return_counts)
    211     if not (-ar.ndim <= axis < ar.ndim):
    212         raise ValueError('Invalid axis kwarg specified for unique')
 
~/.conda/envs/python35/lib/python3.5/site-packages/numpy/lib/arraysetops.py in _unique1d(ar, return_index, return_inverse, return_counts)
    275         aux = ar[perm]
    276     else:
--> 277         ar.sort()
    278         aux = ar
    279     flag = np.concatenate(([True], aux[1:] != aux[:-1]))
 
TypeError: unorderable types: NoneType() < NoneType()

 

 

 

Solution 1

You should not be reusing the same LabelEncoder for multiple columns

https://stackoverflow.com/questions/34750384/whats-with-the-unorderable-types-error

 

Solution 2

Because NULL(None) data loaded

It printed unorderable types: NoneType()

 

check matrix value first
Comments