Transform Labels Back To Original Encoding
I have a table like this: exterior_color interior_color ... isTheftRecovered price 0 Night Black Unknown ... 0 16995.0 1 Orca B
Solution 1:
By encoding as apply(LabelEncoder().fit_transform)
, you lose access to the encoder objects. Instead you can save them in an encoder
dictionary keyed by column name:
from collections import defaultdict
encoder = defaultdict(LabelEncoder)
df[cols] = df[cols].apply(lambda x: encoder[x.name].fit_transform(x))
And then decode the final price via encoder['price']
:
decoded = encoder['price'].inverse_transform(answer)[0]
print(f"Car's price has been predicted as ${decoded:.2f}")
# Car's price has been predicted as $16995.00
Post a Comment for "Transform Labels Back To Original Encoding"