【问题标题】:How can tensorflow feature columns be used for repeatable features?tensorflow 特征列如何用于可重复特征?
【发布时间】:2016-08-09 18:43:11
【问题描述】:

我想训练一个稀疏逻辑回归来将用户分为两类。我的一个特点是用户的兴趣是非排他性的(例如,用户可能对汽车、书籍和食物感兴趣)并且数量可变:一个用户可能有 5 个兴趣,而另一个用户可能只有 3 个,相比之下Deep and Wide tutorial 中显示的示例(年龄、教育等)。我想尽可能地重用深度和广泛教程中的代码,因为最终我想扩展我的模型以拥有一个深度组件。实现这一目标的最简单方法是什么?我也有兴趣保持训练/评分示例的时间复杂度O(active_features)

【问题讨论】:

    标签: tensorflow logistic-regression


    【解决方案1】:

    您可以为每个兴趣创建一个列(一个布尔值,表示是否是他们的兴趣)。如果所有利益都知道,那应该可行。另一种方法是使用 one-hot 编码。

    E.g. Interests are cars, books and food.
    001 is cars
    010 is books
    100 is food
    101 is food and cars
    etc.
    

    如果不是所有兴趣都知道,那么您可以将向量的大小设置为 n+1,为“其他”类别分配额外的空间。

    在 TensorFlow 中,如果您想使用 SKFlow API,可以执行类似的操作。

    x=tf.SparseTensor([[0,1],[1,0]], [1,1], [2,2])
    y=tf.sparse_tensor_to_dense(x)
    input_layer = tf.contrib.layers.real_valued_column('test', 2) # 2 Being the dimension of the inputs
    

    运行它会得到以下结果:

    sess.run(tf.contrib.layers.input_from_feature_columns(columns_to_tensors={'test':y}, feature_columns=[input_layer]))
    array([[ 0.,  1.],
           [ 1.,  0.]], dtype=float32)
    

    【讨论】:

    • 嗨,@craymicheal,你能告诉我如何查看从 csv 读取的值的 crossed_column 的最终结果吗?
    猜你喜欢
    • 1970-01-01
    • 2019-12-12
    • 2018-07-19
    • 1970-01-01
    • 1970-01-01
    • 2011-01-10
    • 2018-06-14
    • 1970-01-01
    • 2021-01-20
    相关资源
    最近更新 更多