如何使用TensorFlow和Estimator同时查看所有特征列转换?


可以使用TensorFlow和Estimator以及“DenseFeatures”方法查看数据集的所有特征列。此数据被转换为NumPy数组,以便可以在控制台上查看。

阅读更多: 什么是TensorFlow以及Keras如何与TensorFlow一起创建神经网络?

我们将使用Keras Sequential API,它有助于构建一个顺序模型,该模型用于处理简单的层堆栈,其中每一层只有一个输入张量和一个输出张量。

包含至少一层卷积层的神经网络被称为卷积神经网络。我们可以使用卷积神经网络来构建学习模型。

我们正在使用Google Colaboratory运行以下代码。Google Colab或Colaboratory有助于在浏览器上运行Python代码,无需任何配置,并可免费访问GPU(图形处理器)。Colaboratory构建在Jupyter Notebook之上。

Estimator使用特征列来描述模型如何解释原始输入特征。Estimator需要一个数值输入向量,特征列将有助于描述模型应该如何转换数据集中每个特征。选择和使用正确的特征列集对于学习有效的模型至关重要。特征列可以是原始特征字典中的原始输入之一,也可以是使用在一个或多个基本列上定义的转换创建的新列。

示例

print("Viewing all feature column transformation together")
tf.keras.layers.DenseFeatures(feature_columns)(example).numpy()

代码来源 −https://tensorflowcn.cn/tutorials/estimator/boosted_trees

输出

Viewing all feature column transformation together
array([[22. , 1. , 0. , 1. , 0. , 0. , 1. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. , 1. , 0. , 0. , 0. ,
7.25, 1. , 0. , 0. , 0. , 0. , 0. , 0. , 1. ,
0. , 0. , 0. , 0. , 0. , 1. , 0. ]], dtype=float32)

解释

  • 所有特征列转换可以一起查看。
  • 可以使用“DenseFeatures”方法实现。
  • 此转换显示在控制台上。

更新于:2021年2月25日

84 次浏览

启动您的职业生涯

通过完成课程获得认证

开始
广告
© . All rights reserved.