I am trying to export an unecoded version of a dataset which was encoded using LabelEncoder (from sklearn.preprocessing
, to enable application of machine learning algorithms) and was subsequently split into training and test datasets (with train_test_split).
I want to export the test data to excel but with the original values. The examples that I've found till now, use the inverse_transform
method of the LabelEncoder on only one variable. I want to apply it automatically on multiple columns that were encoded in the first place.
Here's an example data:
# data
code = ('A B C D A B C D E F').split()
sp = ('animal bird animal animal animal bird animal animal bird thing').split()
res = ('yes, yes, yes, yes, no, no, yes, no, yes, no').split(", ")
data =pd.DataFrame({'code':code, 'sp':sp, 'res':res})
data
Assuming 'res' to be the target variable and 'code' & 'sp' to be the features.
Here you go:
You can do the same for test data.
Here is the full training data (features + variables) for export: