使用 .get_file() 将自定义数据加载到 TensorFlow 中

Loading Custom Data into TensorFlow with .get_file()

我对 Tensor Flow 和 Stack overflow 比较陌生,所以请耐心等待。我的问题如下: 'How do I load in a custom dataset spreadsheet into TensorFlow using the .get_file() method and pandas read method?' 我搜索了 TensorFlow 网站、stack overflow 和其他网站,但它们似乎都使用在线公开可用的数据,或者使用我不理解的不同方法进行一些奇怪的导入。这是我目前拥有的:

import tensorflow as tf
import pandas as pd


CSV_COLUMN_NAMES = ['SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth', 'Species']
SPECIES = ['Setosa', 'Versicolor', 'Virginica']
# This is just some flower data online

train_path = tf.keras.utils.get_file(
    "iris_training.csv", "https://storage.googleapis.com/download.tensorflow.org/data/iris_training.csv")
test_path = tf.keras.utils.get_file(
    "iris_test.csv", "https://storage.googleapis.com/download.tensorflow.org/data/iris_test.csv")
    # I have a spreadsheet on my machine with the exact same data. I want to use those files instead

train = pd.read_csv(train_path, names=CSV_COLUMN_NAMES, header=0)
test = pd.read_csv(test_path, names=CSV_COLUMN_NAMES, header=0)
# Here I am reading a csv file inputting the data, labels, and defining header. Should I use pd.read_excel instead because the files on my machine are excel files?

train_y = train.pop('Species')
test_y = test.pop('Species') # removes answers/thing to predict and test against

非常感谢您的阅读!

如果我没有正确理解你的问题,你想加载自定义 CSV 文件吗?为此,您可以使用 pandas,如下所示:

df = pd.read_csv('file_name.csv', delimiter = ',', encoding='latin-1', header=0)

如果您使用的是 IDE,例如 Jupyter Notebook,您需要在 运行 此命令之前将 csv 下载到 Jupyter notebook。你可以这样做: