0

I'm trying to figure it out how to use the inverse_transform function from LabelEncoder(). For example, in the below code,

from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
df['Label'] = le.fit_transform(df[['Actual']]

If i want to reverse, i can simply call:

le.inverse_transform(df['Label'])

However, i need to apply that same transformation/inverse into a new dataset, which might be predicted from the model above. I.e, it is been done in a new notebook, so, it seems like i have to store the labels. Any ideas how to do this? My only idea is to export a dataframe with 2 columns, and use pd.merge.

bellotto
  • 445
  • 3
  • 13

1 Answers1

0
  1. Make a dictionary containing the inverse transform of that LabelEncoder that you used in 1st notebook. here
  2. And then use that dictionary to remap values in 2nd notebook. here
Adarsh Wase
  • 1,727
  • 3
  • 12
  • 26