如何使用Tensorflow加载来自鲍鱼数据集的csv数据?


可以使用存储此数据集的 Google API 下载鲍鱼数据集。Pandas 库中提供的“read_csv”方法用于将数据从 API 读取到 CSV 文件中。特征名称也明确指定。

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

我们将使用鲍鱼数据集,其中包含一组鲍鱼的测量值。鲍鱼是一种海螺。目标是根据其他测量值预测年龄。

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

import pandas as pd
import numpy as np

print("The below line makes it easier to read NumPy values")
np.set_printoptions(precision=3, suppress=True)

import tensorflow as tf
from tensorflow.keras import layers
from tensorflow.keras.layers.experimental import preprocessing

print("Reading the csv data")
abalone_train = pd.read_csv("https://storage.googleapis.com/download.tensorflow.org/data/abalone_train.csv",
      names=["Length", "Diameter", "Height", "Whole weight", "Shucked weight","Viscera weight", "Shell weight", "Age"])

代码来源:https://tensorflowcn.cn/tutorials/load_data/csv

输出

The below line makes it easier to read NumPy values
Reading the csv data

解释

  • 将所需的包下载到环境中。
  • 使用“read_csv”方法读取 CSV 数据。
  • 数据集中的所有特征都需要被同等对待。
  • 完成后,将特征包装到单个 NumPy 数组中。

更新于: 2021年2月19日

200 次浏览

启动您的 职业生涯

通过完成课程获得认证

开始
广告

© . All rights reserved.