How should I configure my Neural Network to accept a column of numpy.ndarrays as input?

I have a dataframe with 10k rows and the following columns:

      array                                     target
[1,5,6,1,3,etc...]                                5
[3,3,1,0,5,etc...]                                10
[0,0,1,1,7,etc...]                                3
.                                         .
.                                         .
.                                         .


Each array has 33222 elements, so I have 10,000 rows each with a 33,222 long numpy.array that I want to input into a Neural Network to predict the target variable.

Here is how the NN is configured:

x = df.loc[:, 'array']
y = df.loc[:, 'target']

model = Sequential()
model.add(Dense(12, activation='linear'))
model.add(Dense(1, activation='linear'))

model.compile(loss='mse',
optimizer='adam',
metrics=['accuracy', 'mse', 'mae'])

model.fit(x, y, epochs=10, batch_size=1, verbose=1)


I'm getting

"ValueError: Please provide as model inputs either a single array or a list of arrays"


I haven't attempted to use arrays as input for a NN before, so I would also appreciate any advice on the optimal layer choice and configuration for this kind of problem.

1 Answer

You should set the input_shape parameter in the first dense layer. Like this:

model = Sequential()
model.add(Dense(12, activation='linear', input_shape=(33222,)))
model.add(Dense(1, activation='linear'))

• Thank you, so simple, yet it got me confused – Najati Al-imam Aug 28 '20 at 22:13