Tensorflow One Hot Encoder?

后端 未结 15 1731
一生所求
一生所求 2020-12-04 13:46

Does tensorflow have something similar to scikit learn\'s one hot encoder for processing categorical data? Would using a placeholder of tf.string behave as categorical data

15条回答
  •  被撕碎了的回忆
    2020-12-04 14:29

    A simple and short way to one-hot encode any integer or list of intergers:

    a = 5 
    b = [1, 2, 3]
    # one hot an integer
    one_hot_a = tf.nn.embedding_lookup(np.identity(10), a)
    # one hot a list of integers
    one_hot_b = tf.nn.embedding_lookup(np.identity(max(b)+1), b)
    

提交回复
热议问题