如何使用Google colab上传自己的张量数据?

时间:2018-10-11 13:52:00

标签: tensorflow keras google-colaboratory

我一直在在线浏览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列。列1-2包含两组输入,列3包含标签,列3-4包含测试输入数据。

再次,大量的新手,任何帮助都将是惊人的!我很困惑

1 个答案:

答案 0 :(得分:0)

我猜这是问题所在:

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

uploadedfiles.upload命令的结果,并且不包含load_data方法。而是将文件的副本放在本地文件系统上,并返回一个字典,该字典包含每个通过文件名键索引的上载文件的字节。例如:

enter image description here

您已经在DataFrame中以df的形式获取数据。因此,为了进行测试和培训,也许要做一些像这里建议的食谱:How do I create test and train samples from one dataframe with pandas?