Quantcast
Channel: Data Science, Analytics and Big Data discussions - Latest topics
Viewing all articles
Browse latest Browse all 4448

How to Resolve: TypeError: argument must be a string or number

$
0
0

I’m trying to implement below link in the Google Cloud.

Error while running this code from above link:

from sklearn.preprocessing import LabelEncoder

X = np.array(temp.feature.tolist())
y = np.array(temp.label.tolist())

lb = LabelEncoder()

y = np_utils.to_categorical(lb.fit_transform(y))

ERROR:

TypeError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/sklearn/preprocessing/_label.py in _encode(values, uniques, encode, check_unknown)
111 try:
–> 112 res = _encode_python(values, uniques, encode)
113 except TypeError:

3 frames
/usr/local/lib/python3.6/dist-packages/sklearn/preprocessing/_label.py in _encode_python(values, uniques, encode)
59 if uniques is None:
—> 60 uniques = sorted(set(values))
61 uniques = np.array(uniques, dtype=values.dtype)

TypeError: ‘<’ not supported between instances of ‘NoneType’ and ‘str’

During handling of the above exception, another exception occurred:

TypeError Traceback (most recent call last)
in ()
6 lb = LabelEncoder()
7
----> 8 y = lb.fit_transform(y)

/usr/local/lib/python3.6/dist-packages/sklearn/preprocessing/label.py in fit_transform(self, y)
250 “”"
251 y = column_or_1d(y, warn=True)
–> 252 self.classes
, y = _encode(y, encode=True)
253 return y
254

/usr/local/lib/python3.6/dist-packages/sklearn/preprocessing/_label.py in _encode(values, uniques, encode, check_unknown)
112 res = _encode_python(values, uniques, encode)
113 except TypeError:
–> 114 raise TypeError(“argument must be a string or number”)
115 return res
116 else:

TypeError: argument must be a string or number

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 4448

Trending Articles