0
$\begingroup$

I want to change the values of the class labels from nominal into numeric. e.g if the values of a class are {iris-setosa,iris-virginica,iris-versicolor} i want to make them {0,1,2} so the instances will have as a value at the class label the form (0,0,1,2,0,1,1,2,0). Any idea?

$\endgroup$

1 Answer 1

1
$\begingroup$

It's called Label Encoding

In python with the help of scikit-learn you can do following:

le = preprocessing.LabelEncoder() le.fit(["paris", "paris", "tokyo", "amsterdam"])

list(le.classes_)

le.transform(["tokyo", "tokyo", "paris"])

list(le.inverse_transform([2, 2, 1]))

Documentation for more info: https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.LabelEncoder.html

PS: Label Encoding might be responsible for unintentional ordering of possible values. I.E. model might think that nominal value with associated numerical value 2 is more important than the nominal value with associated numerical value 1. The solution is One Hot Encoding.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.