labelencoder update

Solutions on MaxInterview for labelencoder update by the best coders in the world

showing results for - "labelencoder update"
Kevin
15 May 2017
1# train and test are pandas.DataFrame's and c is whatever column
2le = LabelEncoder()
3le.fit(train[c])
4test[c] = test[c].map(lambda s: '<unknown>' if s not in le.classes_ else s)
5le.classes_ = np.append(le.classes_, '<unknown>')
6train[c] = le.transform(train[c])
7test[c] = le.transform(test[c])