如何在Keras中将'mnist.load_data()'返回值的格式更改为'mnist_train.csv'? [英] how to change the format of the return value of 'mnist.load_data()' to 'mnist_train.csv' in Keras?
问题描述
我使用Keras.
(X_train, y_train), (X_test, y_test) = mnist.load_data()
X_train'的形状为(number_of_training_sample,224,224,3)
X_train' shape is (number_of_training_sample,224,224,3)
Y_train的形状为(number_of_training_sample, 10)
Y_train's shape is (number_of_training_sample, 10)
功能和标签在不同的ndarray中分开. 但是我想将这些ndarrays更改为'mnist_train.csv'格式. ( https://raw.githubusercontent.com/sjwhitworth/golearn /master/examples/datasets/mnist_train.csv )
Features and labels are separated in different ndarray. BUT I want to change these ndarrays to 'mnist_train.csv' format. (https://raw.githubusercontent.com/sjwhitworth/golearn/master/examples/datasets/mnist_train.csv)
我自己的数据集的格式与返回值'mnist.load_data()'完全相同.但是在我要使用的代码中只能使用"mnist_train.csv"格式.
My own dataset is totally same format with the return value of 'mnist.load_data()'. BUT only 'mnist_train.csv' format is worked in the code that I want to use.
您能让我知道如何更改格式吗???? (很抱歉,这个问题很简单.我是numpy和python的新手.)
Could you let me know how to change the format???? (Sorry for really simple question.. I am a newbie of numpy and python.)
推荐答案
(X_train, y_train), (X_test, y_test) = mnist.load_data()
将数据作为numpy数组加载
loads data as numpy arrays
'mnist_train.csv'是硬盘上的.csv文件存储,我们通常使用pandas库读取
'mnist_train.csv' is a .csv file store on a hard disc which we usually read with pandas library
import pandas as pd
X_train = pd.read_csv('filename.csv')
Pandas读取一个.csv作为数据框(如果有列名称,则带有列名称) 使用keras,您需要numpy数组,因此
Pandas reads a .csv as a dataframe (with column names if there are such) Using keras you need numpy arrays, so the
(X_train, y_train), (X_test, y_test) = mnist.load_data()
应该可以正常工作
发布您正在使用的代码以及所产生的错误以供进一步解释
Post the code you are using and the errors that is produced for further explaination
这篇关于如何在Keras中将'mnist.load_data()'返回值的格式更改为'mnist_train.csv'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!