python


ValueError when compiling with Keras Sequential()


I'm trying to compile a dataset with Sequential() with the Keras module, but I get back a value error:
ValueError: Error when checking model input: expected dense_input_1 to have shape (None, 33) but got array with shape (32, 36)
I went through my code many times, but couldn't find any possible error.
I have a dataset with 32 items, all which are converted into floats.
Here is the code for my neural network:
# Build neural network
# Sequential
model = Sequential()
# Neural network
model.add(Dense(36, input_dim=34, init='uniform', activation='sigmoid' ))
model.add(Dense(32, init='uniform', activation='sigmoid'))
model.add(Dense(32, init='uniform', activation='sigmoid'))
model.add(Dense(32, init='uniform', activation='sigmoid'))
model.add(Dense(33, init='uniform', activation='sigmoid'))
# Compile model
model.compile(loss='mean_squared_logarithmic_error', optimizer='SGD', metrics=['accuracy'])
# Fit model
history = model.fit(X, Y, nb_epoch=20, validation_split=0.2, batch_size=3)
Here is the complete error message I received:
Traceback (most recent call last):
File "/Users/cliang/Desktop/Laurence/Python/Programs/Python/Collaborative_Projects/Cancer_screening/neural_network_alls_1.py", line 111, in <module>
history = model.fit(X, Y, nb_epoch=20, validation_split=0.2, batch_size=3)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/models.py", line 672, in fit
initial_epoch=initial_epoch)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/engine/training.py", line 1116, in fit
batch_size=batch_size)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/engine/training.py", line 1029, in _standardize_user_data
exception_prefix='model input')
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/engine/training.py", line 124, in standardize_input_data
str(array.shape))
ValueError: Error when checking model input: expected dense_input_1 to have shape (None, 34) but got array with shape (32, 36)
As the error say, you have a miss match between your input data shape and the first layer. You clearly define that your input dimension is (number of features) is 34 input_dim=34, though you are passing data with 36 features.
I think you have confused between the number of neurons of the hidden layer 36 and your input data 34. Either you drop two column from your data or change input_dim=36.

Related Links

How does str(list) work?
Django Bad File Descriptor on live server
Why is My Django Form Executed Twice?
In matplotlib, what's the difference between title() and suptitle()?
Modifying and rewriting .csv files in Python
How do I scroll to a certain widget in a QScrollArea
NoSuchKey when getting a signed url for a cloudstorage object with a space in the name
Not sure how to parse this
Error drawing 3D graph in python
How to change objects in a python script by using a keyboardinterrupt for specific keys?
Arguments to an object's parent's function
python regex ignoring underscore incorrectly
Will installing Anaconda3 change Mac OS X default Python version to 3.4?
Devices Labels. Python Code Debugging
Adding list of values to rows, turning the dataframe into long format afterwards
bottle_mysql Encoding failure

Categories

HOME
npm
rotation
mapping
webrtc
bower
thunderbird-addon
hana
flyway
filter
actionscript-2
lotus-notes
criteria
abcpdf
mongodb-query
nuxt.js
jacoco
alfresco-share
prestodb
ip-camera
azure-servicebus-queues
philips-hue
activepython
data-cleansing
hanami
partial-application
gzip
ivy
spring-profiles
fabric-digits
pace
vsts-package-management
code-behind
restful-url
asmx
3scale
startapp
ajp
fqdn
walmart-electrode
istorage
webdatagrid
persistent
cgcontext
etherpad
photography
react-native-fbsdk
pycurl
iphone-developer-program
jcreator
collapsingtoolbarlayout
ingres
build-process
gradle-script-kotlin
push-diffusion
manifest.mf
rmongodb
icefaces
chessboard.js
try-finally
radians
instruments
unsatisfiedlinkerror
codesign
gradle-release-plugin
group-concat
asp.net-mvc-2
except
galaxy
cctray
loose-typing
datainputstream
kendo-menu
qbfc
calibration
castle-windsor-3
cpan
django-1.6
activity-streams
line-numbers
grunt-contrib-concat
genetic-programming
libssh2
delphi-xe3
mbox
visual-c++-2010-express
sim900
modeshape
argb
symphony-cms
pep8
domain-calculus
angularjs-timeout
dynamic-data
couchdb-lucene
n-layer
z-machine
entity-framework-ctp5
nintendo
hashalgorithm
throttling
nemerle
coff
collect
adsl
svn-hooks
hibernate3-maven-plugin
gwt-2.2-celltable
rtsp-client
iphone-sdk-3.2
code-design
oggvorbis
visual-studio-dbpro

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App