1
$\begingroup$

Are there any differences between get_dummies and labelbinarizer in terms of what they want to achieve? It seems to be both will somehow do a one-hot encoding.

$\endgroup$
1
$\begingroup$

A couple of things comes to mind.

get_dummies can transform a dataframe with many columns, whereas LabelBinarizer will only do one column.

get_dummies outputs a dataframe (if the input is a dataframe) with a nicely formatted columns, whereas LabelBinarizer outputs a numpy array, so if you want to attach labels to them, you'd need to get them from the fitted instance of the LabelBinarizer.

Inverse transform is more intuitive with LabelBinarizer, it has a method named inverse_transform, whereas with get_dummies you would need to do something like dummies.idxmax(axis=1)

So overall, get_dummies seems to be a better choice

|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.