Reputation: 53
My Original Dataset is of the shape (210,8) and I'm trying to give the 7 Independent Variables as Input to my Neural Network to see which Class/Category they belong to. The Class/Category is the Target Variable.
I have separated the independent variables and stored them in 'df_test' as an array
df = pd.read_csv('https://raw.githubusercontent.com/siiddd/WheatSeeds/master/Wheat.csv')
features = ['Area', 'Perimeter', 'Compactness', 'Length of Kernel','Width of Kernel', 'Asymmetric Coeff.', 'Length of Kernel Groove']
dftoArray = df[features].to_numpy()
df_test = dftoArray.reshape(7,210)
model = keras.Sequential()
model.add(keras.Input(shape = (7, )))
model.add(keras.layers.Dense(500, activation = 'relu'))
model.add(keras.layers.Dense(1, activation = 'sigmoid'))
model.compile(optimizer = 'adam', loss = 'sparse_categorical_crossentropy', metrics = ['accuracy'])
model.fit(df_test, df['Class'], epochs = 10, validation_split = 0.10)
This gives me the error:
Error when checking input: expected input_18 to have 3 dimensions, but got array with shape (7, 210)
Upvotes: 2
Views: 62
Reputation: 4289
I think you are making a mistake while reshaping the DataFrame
. As you said, the data consists of 210 samples each having 8 features i.e the shape of the data must be ( 210 , 8 )
. Now, after selecting the desired columns from the df
you need to reshape your data to ( 210 , 7 )
and not ( 7 , 210 )
. Make this change,
df_test = dftoArray.reshape( 210 , 1 )
Shapes ( 210 , 7 )
and ( 7 , 210 )
have a huge difference. The shape ( 7 , 210 )
refers to a dataset which consists of 7 samples with 210 features each. This is not the case.
Upvotes: 1