【问题标题】:How do I upload my own data for tensor flow using google colab?如何使用 google colab 为 tensorflow 上传自己的数据?
【发布时间】:2018-10-11 13:51:59
【问题描述】:

我一直在看网上的tensorflow教程(特别是房价教程:https://colab.research.google.com/github/tensorflow/models/blob/master/samples/core/tutorials/keras/basic_regression.ipynb

我一直在尝试使用 google colab 为类似项目上传自己的 csv 文件。但我似乎无法获得正确的格式 - 我对此很陌生,所以我找不到我能理解的解决方案。

from __future__ import absolute_import, division, print_function

import tensorflow as tf
from tensorflow import keras

import numpy as np
import pandas as pd

print(tf.__version__)

#Import the csv files

from google.colab import files
uploaded = files.upload()

for fn in uploaded.keys():
  print('User uploaded file "{name}" with length {length} bytes'.format(
  name = fn, length = len(uploaded[fn])))

# This is where I upload my csv file

import io

df = pd.read_csv(io.StringIO(uploaded[ 'data.csv'].decode('utf-8')))
df.head()

(train_data, train_labels), (test_data, test_labels) = uploaded.load_data()

# Shuffle the training set
order = np.argsort(np.random.random(train_labels.shape))
train_data = train_data[order]
train_labels = train_labels[order]
print(boston_housing)

这就是问题所在 - 我似乎无法将我的数据分成训练和测试数据。

我的 data.csv 只有 5 列。 Col 1-2 包含两组输入,col3 包含标签,col 3-4 包含测试输入数据。

再次,大量新手,任何帮助都会很棒!我很困惑

【问题讨论】:

    标签: tensorflow keras google-colaboratory


    【解决方案1】:

    我猜这行是问题所在:

    (train_data, train_labels), (test_data, test_labels) = uploaded.load_data()
    

    uploadedfiles.upload 命令的结果,不包括load_data 方法。相反,它将文件的副本放在本地文件系统上,并返回一个字典,其中包含由文件名键索引的每个上传文件的字节。例如:

    您已经在df 中获得了DataFrame 的数据。所以,为了分成测试和训练,也许做一些像这里建议的食谱:How do I create test and train samples from one dataframe with pandas?

    【讨论】:

      猜你喜欢
      • 2019-08-11
      • 2018-05-08
      • 1970-01-01
      • 1970-01-01
      • 2020-05-08
      • 1970-01-01
      • 2017-04-21
      • 2022-08-15
      • 2020-02-02
      相关资源
      最近更新 更多