Keras shape of features for training
<p>I'm trying to train nn with keras <code>train_on_batch</code> function. I have 39 features and want a batch to contain 32 samples. So I have a list of 32 numpy arrays for every training iteration. </p>

<p>So here is my code(here every batch_x is a list of 32 numpy array each containing 39 features):</p>

<pre><code>input_shape = (39,)

model = Sequential()
model.add(Dense(39, input_shape=input_shape)) # show you is only first layer
... 

for batch_x, batch_y in train_gen:
    model.train_on_batch(batch_x, batch_y)
</code></pre>

<p>But suddenly I got an error:</p>

<pre><code>Exception: Error when checking model input: the list of Numpy arrays
that you are passing to your model is not the size the model expected.
Expected to see 1 arrays but instead got the following list of 32 arrays:
</code></pre>

<p>I'm not really sure what's wrong.</p>

<p>P.S. I also tried different <code>input_shape</code> such as (32, 39), (39, 32) etc.</p>

<p>You don't want 32 arrays of size 39, you want one array of size (32, 39). </p>

<p>So you must change input_shape to (None, 39), the None allowing you to dynamically change your batch_size, and change batch_x to be a numpy array of shape (32, 39).</p>

python python-2.7 machine-learning keras training-data