将 .csv 加载到 tensorflow 时出错 [英] Error loading .csv into tensorflow

查看:37
本文介绍了将 .csv 加载到 tensorflow 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我采用了在 Iris csv 上训练的预制代码,并尝试使用我自己的 csv.

I've taken the prefabricated code that trains on the Iris csv and attempted to use my own csv.

错误发生在这里

train_data = "train_data.csv"
test_data = "test_data.csv"

training_set = tf.contrib.learn.datasets.base.load_csv_with_header(
filename=train_data,
target_dtype=np.int,
features_dtype=np.float32)

有错误

ValueError: invalid literal for int() with base 10: 'feature1'

csv 看起来像这样

feature1,feature2,feature3,label
1028.0,1012.0,1014.0,1
1029.0,1011.0,1017.0,-1
1027.0,1013.0,1015.0,1
...(and so on)

我知道错误是试图说 feature1 不是整数.但是,当我对 Iris 数据集使用相同的代码时,有些字符串标头未用作张量.鸢尾花数据 csv 如下所示.

I get that the error is trying to say that feature1 is not an integer. However, when I use the same code for the Iris dataset, there are string headers that are not used as tensors. The Iris data csv looks like this.

30,4,setosa,versicolor,virginica
5.9,3.0,4.2,1.5,1
6.9,3.1,5.4,2.1,2
5.1,3.3,1.7,0.5,0

另外,不确定我是否应该提出不同的问题,但我将功能标题更改为

Also, not sure if I should make this a different question, but I changed the feature headers to

1,2,3,4
1028.0,1012.0,1014.0,1
1029.0,1011.0,1017.0,-1
1027.0,1013.0,1015.0,1
...(and so on)

我现在收到这个错误

ValueError: could not broadcast input array from shape (3) into shape (2)

非常感谢任何想法或帮助!谢谢!!!

Any ideas or help are greatly appreciated! Thanks!!!

推荐答案

如果您要使用此功能,您必须以预期的格式编写数据集.第一行应该是这样的:

If you are going to use this function, you have to write the dataset in the expected format. The first row should be like:

n_samples, n_features, [feature names]

例如,您显示的 iris 数据集的格式正确:

For example, the one for the iris dataset you are showing has the correct format:

30,4,setosa,versicolor,virginica

即30 个样本 4 个特征

i.e. 30 samples 4 features

如果您创建的数据集中有 50 个样本,它应该是这样的:

If you have 50 samples in the dataset you created it should be like:

50,4,labelname
1028.0,1012.0,1014.0,1
1029.0,1011.0,1017.0,-1
1027.0,1013.0,1015.0,1
...(and so on)

这篇关于将 .csv 加载到 tensorflow 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆