【问题标题】:tensorflow wide model: how to use one-hot feature?tensorflow 宽模型:如何使用 one-hot 功能?
【发布时间】:2017-01-25 15:10:25
【问题描述】:

我在https://www.tensorflow.org/versions/r0.9/tutorials/wide_and_deep/index.html 中阅读了有关该模型的信息 文章中的特征有两种类型:Categorical 和 Continuous

在我的例子中,我有一个描述用户 ID 的列,范围从 0 到 10000000

我将此列视为 Categorical 并使用 hash-bucket ,但仅获得大约 0.50010 的池 auc 值

1)是否需要使用one-hot来处理这个id列?

2)如果需要,如何实现?我找到了一个 "tf.contrib.layers.one_hot_encoding" ,但它不支持列名,所以不能在wide-n-deep demo中使用。

【问题讨论】:

    标签: tensorflow


    【解决方案1】:

    不,您不需要对 UserID 列进行编码。每个值都是唯一的,不是分类值。当类别少于 1000 个时,一次热编码是有意义的。

    要回答您关于如何使用 one_hot_encoding 的问题,假设您有一个标签列表(注意它们必须是整数):

    import tensorflow as tf
    
    with tf.Session() as sess:
        labels = [0, 1, 2, 3]
        labels_t = tf.constant(labels)
        num_classes = len(labels)
    
        one_hot = tf.contrib.layers.one_hot_encoding(labels_t, num_classes=num_classes)
        print(one_hot.eval())
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-07
    • 2021-10-09
    • 1970-01-01
    • 1970-01-01
    • 2017-05-14
    • 2018-03-30
    • 2018-05-09
    • 2018-09-11
    相关资源
    最近更新 更多