Label Encoder - Use of Inverse_transform function

997 Views Asked by At

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.

1

There are 1 best solutions below

0
On
  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