Reputation: 1
Hello I was doing a competition for a kaggle but then while I was practicing with Keras, I encountered a serious problem. The error is "ValueError: Error when checking input: expected dense_9_input to have shape (24,) but got array with shape (0,)". I tried to solve this problem by looking through Stack overflow but I couldn't find a right answer.
The variable X contains all the variables except the target value which is winPlacePerc and string variables such as ID, match id and group id.
#Libraries
from keras.models import Sequential
from keras.layers import Dense
import numpy as np
import pandas as pd
import tensorflow as tf
seed = 0
np.random.seed(seed)
tf.set_random_seed(seed)
train = pd.read_csv("train_V2.csv")
X = train.iloc[:,3:1]
Y = train.iloc[:,-1]
model = Sequential()
model.add(Dense(8, input_dim=24,activation='relu'))
model.add(Dense(8, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam',metrics=['accuracy'])
model.fit(X, Y, epochs=200, batch_size=10)
print("\n Accuracy: %.4f" % (model.evaluate(X, Y)[1]))
The Data set can be found here :https://www.kaggle.com/overload10/pubg-predicting-chicken-dinner/data
I am here for comments to solve this problem. I started learning Tensorflow/ Keras right after doing Automate the Boring Stuff with Python, so I am a super duper noob. I take comments, and advises. Thank you for looking at my first question. Please help! :((((
Upvotes: 0
Views: 758
Reputation: 241
Your input of Keras does not match your numpy array. Figure out the size of your numpy array and change the input shape accordingly. In case of more than 2 dimensions use a flatten layer before dense layers.
Remember that the first dimension of your np array will be interpreted as the batch size
Upvotes: 2