如何使用 Tensorflow 与 Estimators 来分割鸢尾花数据集?
tensorflowserver side programmingprogramming更新于 2025/5/21 11:52:17
可以通过删除不相关的特征来提取鸢尾花数据集中的关键特征/列名。这可以使用‘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://www.tensorflow.org/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"功能已删除。
- 其余列与示例数据一起显示在控制台上。

