【问题标题】:Can tf.contrib.layers.sparse_column_with_integerized_feature handle categorical features with multiple inputs within one column?tf.contrib.layers.sparse_column_with_integerized_feature 可以在一列中处理具有多个输入的分类特征吗?
【发布时间】:2017-06-09 21:58:00
【问题描述】:

我只是使用 Tensorflow 及其 tf.learn api 来创建和训练 DNNRegressor 模型。我有一个多价的整数特征列(对于每一行,我可以在该列中有多个整数值),我为此特征列使用 tf.contrib.layers.sparse_column_with_integerized_feature。

现在我的问题是 csv 文件中多价特征列的正确分隔符是什么。 例如,假设我有一个 csv,其中 col2 是多价特征,它不是一个热门特征:

  1, 2, 1:2:3:4, 5
  2, 1, 4:5, 6

如您所见,我在 col2 中使用 ':' 来分隔整数特征值,但它似乎不正确,并且在运行 DNNRegressor 并将此特征列声明为 tf.contrib.layers.sparse_column_with_integerized_feature 时出现此错误:

 'Value passed to parameter 'x' has DataType string not in list of allowed 
  values: int32, int64, float32, float64'.

非常感谢您的帮助

【问题讨论】:

    标签: python machine-learning tensorflow deep-learning


    【解决方案1】:

    tf.contrib.layers.sparse_column_with_integerized_feature 仅适用于 int32int64 值,因此它不会完全按照您的意愿工作。

    tensorflow 支持数字列中的多维,因此您可以使用tf.feature_column.numeric_column 并指定您拥有的shape。请注意,tensorflow 会期望所有这些形状都是相同的,因此您需要将所有值填充到一个通用形状。

    冒号 ':' 分隔符适用于多价列,here's an example 如何使用 pandas 将多个值读入 DataFrame(问题是关于 XML,但同样适用于 CSV)。您可以将此数据框作为input_fn 传递给model.train() 函数。

    【讨论】:

      猜你喜欢
      • 2017-06-28
      • 2018-04-12
      • 2017-06-17
      • 2019-06-13
      • 2014-09-03
      • 2021-12-17
      • 2018-03-22
      • 2021-01-01
      • 2021-05-08
      相关资源
      最近更新 更多