Is there a smart way to change categorical features into one-hot encoding, then run a linear regression model and get estimated parameters along with the names of the variables that they refer to (in python)? I have used a OneHotEncoder to change categorical features into 1-0 variables, but I feel I have no control over this process (Laet on I cant match coefficients with their "real" names).
Asked
Active
Viewed 43 times
1 Answers
0
If you one-hot encoded with Pandas, this question already has an answer: Reversing 'one-hot' encoding in Pandas.
Generally, if you have your list of classes
classes = ['cats', 'dogs', 'mice']
and you have a one-hot-encoded vector
one_hot = [0, 1, 0]
, you can match it back with
classes[one_hot ==1 ]
If you have many one-hot encoded labels, you can map this expression over the list of one-hot encoded labels to obtain the decoded class labels.

Julia K
- 397
- 3
- 10