# Keras Value Error

Not new to Python or programming but I'm fairly new to machine learning so I was hoping I'm just overlooking something simple. At the moment I keep running into an issue where Keras spits out the following Value Error:

ValueError: Error when checking input: expected flatten_input to have 3 dimensions, but got array with shape (483, 1)


So to provide some context and show you all the bit of code I'm working with, please refer to the example below.

# for the sake of argument, let's say we are feeding in an array of floats labeled 'getReturns'
# in this case, lets say 'getReturns' contains a total of 569 values

trainingLen = int(float(len(getReturns)) * 0.85) # reserves 85 percent for training

trainingData = getReturns[:trainingLen]
testingData = getReturns[trainingLen:-1]

model = keras.Sequential()

model.compile(optimizer = "adam", loss = "sparse_categorical_crossentropy", metrics = ["accuracy"])

model.fit(trainingData, testingData, epochs = 5)


Though it may be obvious, the "model.fit" line is the one causing the actual error but I suspect something is wrong with the way I am bringing in data? I'm not sure if I need to reshape my array somehow or if the problem is stemming from something even more fundamental? Any help would be appreciated.

Thanks, -B

• if your input shape 'getReturns' contains a total of 569 values, then the input shape parameter in keras should be "input_shape=(1,)", we don't include number of instances/observations when setting up the model (afterall Keras shouldn't know whether we have 1 million or 100 observations) – chappers Apr 18 at 22:14
• Thanks, chappers. So after taking your advice I ran into another error and had to split the training and testing samples equally. Luckily that worked and I am now getting no errors! Only issue is when I run the code now, I end up with a '0.00' accuracy after training. Any thoughts? – bg07 Apr 18 at 23:42

In the code of your model, you have split up the dataset into 85% training and 15% testing dataset. However, model.fit() takes as input the features and the target variable. In your case, you have not defined the target variable for either the training or the test case. Also, as pointed out by @chappers in the comment section, you don't have to specify the batch size in the input_size. The correct way to do it is as follows:

# for the sake of argument, let's say we are feeding in an array of floats labeled 'getReturns'
# in this case, lets say 'getReturns' contains a total of 569 values
# in this case, consider 'getReturnsLabels' contains a total of 569 values with each value representing a specific class.

trainingLen = int(float(len(getReturns)) * 0.85) # reserves 85 percent for training

trainingData = getReturns[:trainingLen]
testingData = getReturns[trainingLen:-1]

trainingDataLabels = getReturnsLabels[:trainingLen]
testingDataLabels = getReturnsLabels[trainingLen:-1]

model = keras.Sequential()