Home > database >  Is there any difference between keras.utils.to_categorical and pd.get_dummies?
Is there any difference between keras.utils.to_categorical and pd.get_dummies?

Time:12-17

I think the same purpose among sklearn.OneHotEncoder, pandas.get_dummies, and keras.to_categorical. But I don't know the difference. 

CodePudding user response:

Apart from the difference of the output/input type there is no difference, they all achieve the same result.

There's some technical difference:

  • Keras is very simple, you give him the target vector and he one -hot encodes it, use keras if you need to encode the labels vector.

  • Pandas is the most complex, it creates a new column for every class of the data, the good part is that works on dataframes where you want to one-hot only one of the columns (so you could say this is more of a multi purpose method, but not the preferable option if you need to train a NN)

  • Sklearn lets you one-hot encode multiple features in the same variable, is a bit more flexible that the use keras offers, if the method from keras is too simple try with sklearn, if keras is enough stick with it.

  • Related