-1

I wanted to predict some string values using unsupervised learning. I converted a categorical column into numerical by using label encoding and predicted the values. Now I want to know the string values of the predicted numerical values(label encoded values)

input: predictedvalues = [1,2,4]

output: 1-car
        2-bike
        4-cars
krish
  • 61
  • 9

1 Answers1

1

Since you haven't mentioned the library used for label encoding, I'll presume you are using sklearn. If so, then you can use the inverse_transform() function.

from sklearn import preprocessing

le = preprocessing.LabelEncoder()
le.fit(['car', 'bike', 'cars'])

print(le.classes_)

le.transform(['car', 'bike', 'cars'])

Output: array([1, 0, 2])

Now let's invert the output

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

Output: array(['car', 'bike', 'cars'], dtype='<U4')

Here's a link to a live executable Deepnote notebook if you wish to test the code above.

Tejas
  • 123
  • 1
  • 7