Tensorflow One Hot Encoder?

后端 未结 15 1727
一生所求
一生所求 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:42

    My version of @CFB and @dga example, shortened a bit to ease understanding.

    num_labels = 10
    labels_batch = [2, 3, 5, 9]
    
    sparse_labels = tf.reshape(labels_batch, [-1, 1])
    derived_size = len(labels_batch)
    indices = tf.reshape(tf.range(0, derived_size, 1), [-1, 1])
    concated = tf.concat(1, [indices, sparse_labels]) 
    labels = tf.sparse_to_dense(concated, [derived_size, num_labels], 1.0, 0.0)
    

提交回复
热议问题