如何将数据输入Keras?具体来说,如果我有多于2列,则x_train和y_train是什么? [英] How to input data into Keras? Specifically what is the x_train and y_train if I have more than 2 columns?

查看:334
本文介绍了如何将数据输入Keras?具体来说,如果我有多于2列,则x_train和y_train是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将数据输入到keras中?有什么结构?具体来说,如果我有两列以上,则x_train和y_train是什么?

How can I input data into keras? What is the structure? Specifically what is the x_train and y_train if I have more than 2 columns?

这是我要输入的数据:

我试图在此示例中定义Xtrain,Keras在其多层感知器神经网络代码中文档。 ( http://keras.io/examples/ )这是代码:

I am trying to define Xtrain in this example Multi Layer Perceptron Neural Network code Keras has in its documentation. (http://keras.io/examples/) Here is the code:

from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation
from keras.optimizers import SGD

model = Sequential()
model.add(Dense(64, input_dim=20, init='uniform'))
model.add(Activation('tanh'))
model.add(Dropout(0.5))
model.add(Dense(64, init='uniform'))
model.add(Activation('tanh'))
model.add(Dropout(0.5))
model.add(Dense(2, init='uniform'))
model.add(Activation('softmax'))

sgd = SGD(lr=0.1, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='mean_squared_error', optimizer=sgd)

model.fit(X_train, y_train, nb_epoch=20, batch_size=16)
score = model.evaluate(X_test, y_test, batch_size=16)

编辑(其他信息):

在这里查看:什么是Python Keras深度学习包的数据类型?


Keras使用包含theano.config.floatX浮点类​​型的numpy数组。可以在您的.theanorc文件中进行配置。通常,对于CPU计算,它将是float64;对于GPU计算,它将是float32,尽管如果您愿意,也可以在使用CPU时将其设置为float32。您可以通过以下命令创建正确类型的零填充数组

Keras uses numpy arrays containing the theano.config.floatX floating point type. This can be configured in your .theanorc file. Typically, it will be float64 for CPU computations and float32 for GPU computations, although you can also set it to float32 when working on the CPU if you prefer. You can create a zero-filled array of the proper type by the command



X = numpy.zeros((4,3), dtype=theano.config.floatX)

问题:步骤1看起来像使用excel文件中的上述数据创建浮点numpy数组。我该如何处理获胜者专栏?

Question: Step 1 looks like create a floating point numpy array using my above data from the excel file. What do I do with the winner column?

推荐答案

这完全取决于您的需求。

It all depends on your need.

您似乎想根据A-N列中的参数预测获胜者。那么您应该将 input_dim 定义为14,然后 X_train 应该是(N,14)numpy数组,如下所示:

It looks like that you want to predict the winner based on the parameters shown in column A - N. Then you should define input_dim to be 14, and X_train should be an (N,14) numpy array like this:

[
   [9278,  37.9, ...],
   [18594, 36.3, ...],
   ...
]

似乎您的预测集仅包含2个项目(2个总统候选人大声笑),因此您应该对答案进行编码 Y_train 在(N,2)numpy数组中,如下所示:

It seems that your prediction set only contains 2 items ( 2 president candidates LOL), so you should encode the answer Y_train in an (N,2) numpy array like this:

[
   [1, 0],
   [1, 0],
   ...
   [0, 1],
   [0, 1],
   ...
]

其中 [1,0] 表示巴拉克·奥巴马(Barack Obama)是赢家,反之亦然。

where [1,0] indicates that Barack Obama is the winner and vice versa.

这篇关于如何将数据输入Keras?具体来说,如果我有多于2列,则x_train和y_train是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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