I'm working on a classification project and need to do one hot encoding on my data set. I'm just wondering what is the difference between tf.keras.backend.one_hot and keras.utils.to_categorical, and is one of them preferred over the other?
Asked
Active
Viewed 1,413 times
5
ebrahimi
- 1,277
- 7
- 20
- 39
kimchilover123
- 51
- 2
1 Answers
6
The difference is the input and output.
The utils.to_categorical function takes a vector as input and returns a matrix with one hot encoded rows.
The backend.one_hot can be called as a transformation step inbetween a compute sequence of tensors.
It takes nD tensor as input and returns n+1 D one hot encoded tensor.
Peter
- 7,277
- 5
- 18
- 47
mahesh ghanta
- 396
- 1
- 3