python - 如何使用对字符串列正确的tensorflow数据集映射函数
问题描述
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
你能帮忙吗?
解决方案
您可以将 bool 转换为 int:
y = tf.equal(features["str_col"], 'YES')
y = tf.cast(y, tf.int32)
推荐阅读
- splunk - 我可以在 Splunk 中动态引用令牌吗?
- sql - 如何在 SQL 的新列中使用案例信息?
- reactjs - 使用 React 路由器时直接访问子文件夹?
- snowflake-cloud-data-platform - 为什么在此作业运行中总分区数为 1 而扫描的分区数更大?
- python - ImportError:无法导入名称“urlencode”
- sap-cloud-platform - CF 子域的 mta.yaml 中是否有任何占位符表示法?
- python - pandas multiIndex.from_product 并附加一列?
- css - CSS:重复的动画背景
- algorithm - 具有正权重和直径 D 的图中的单源最短路径
- java - 如何使用错误解码器抛出异常/获取数据 - OpenFeign