如何将数据输入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?

如何将数据输入keras?结构是什么?具体来说,如果我有超过 2 列,x_train 和 y_train 是什么?

这是我要输入的数据:

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

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)

编辑(补充信息):

看这里:

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 数组。我如何处理获胜者列?

这完全取决于您的需要。

看来你要根据A-N列的参数来预测赢家,那么你应该定义input_dim为14,X_train应该是一个(N ,14) 像这样的 numpy 数组:

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

您的预测集似乎只包含 2 个项目(2 个总统候选人 LOL),因此您应该将答案 Y_train 编码在一个 (N,2) numpy 数组中,如下所示:

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

其中 [1,0] 表示巴拉克奥巴马获胜,反之亦然。