如何使用 Estimators 在 Tensorflow 中分割鸢尾花数据集?


可以通过删除不相关的特征来提取鸢尾花数据集的关键特征/列名。这可以使用“pop”方法来完成。

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

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

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

TensorFlow Text 包含一系列与文本相关的类和操作,可用于 TensorFlow 2.0。TensorFlow Text 可用于预处理序列建模。

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

Estimator 是 TensorFlow 中对完整模型的高级表示。它旨在实现轻松扩展和异步训练。

示例

print("Species feature is deleted")
train_y = train.pop('Species')
test_y = test.pop('Species')
print("After deleting the column, sample data is being displayed")
train.head()

代码来源 −https://tensorflowcn.cn/tutorials/estimator/premade#first_things_first

输出

Species feature is deleted
After deleting the column, sample data is being displayed
SepalLength SepalWidth PetalLength PetalWidth
0  6.4  2.8  5.6  2.2
1  5.0  2.3  3.3  1.0
2  4.9  2.5  4.5  1.7
3  4.9  3.1  1.5  0.1
4  5.7  3.8  1.7  0.3

解释

  • “species”特征被删除。
  • 其余列与示例数据一起显示在控制台上。

更新于: 2021年2月22日

144 次浏览

开启你的职业生涯

通过完成课程获得认证

开始学习
广告
© . All rights reserved.