【问题标题】:how to use tensorflow dataset map function correct for string column如何使用对字符串列正确的tensorflow数据集映射函数
【发布时间】:2021-01-24 14:18:09
【问题描述】:

m 使用 tensorflow 数据集 api

我有一个字符串列的数据可以代表一个二元选项

(类似(“是”或“否”)

我想知道我是否将其分别转换为 1 和 0(整数值),而其他列保持不变

我的骨架函数是:

def mapper(features,target):
    #features["str_col"] TODO "MAP this when yes to 1 when no to 0"

    #return features with x transformed # TODO

你能帮忙吗?

【问题讨论】:

标签: python tensorflow tensorflow2.0 tensorflow-datasets


【解决方案1】:

您可以将 bool 转换为 int:

y = tf.equal(features["str_col"], 'YES')
y = tf.cast(y, tf.int32)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-05
    • 2020-06-17
    • 2020-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-14
    • 1970-01-01
    相关资源
    最近更新 更多