Skip to main content
1 of 2
Rob
  • 49
  • 2
  • 8

Reverse a label encoded target in test and train series?

when performing a Scikit train/test split like so:

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)

with categorical target values (y from above) already label encoded :

class_le = LabelEncoder()
aDataFrame['aTarget'] = class_le.fit_transform(aDataFrame['aTarget'].values)  

I can run a classification report from the result of a classification:

print (classification_report(results, y_test))

that prints out info about the precision:

         precision    recall  f1-score   support

      0       1.00      1.00      1.00        18
      1       0.40      0.25      0.31         8
      2       0.08      0.10      0.09        10

Is there a way to say what decoded category each of those results referred to?

How can I determine what the already encoded target values were before encoding? For example, if I print out the contents of the y_train, y_test variables I'll see a series like so:

    aTarget
12799   192
145162  15
140041  205

Just looking at the target of 192, how would I determine what category it originally referred to given the original class_le label encoding object? thanks very much for any tips!

Rob
  • 49
  • 2
  • 8