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

Python: Return function won’t return a list
Which python Linux IDEs support GAE's webapp2 framework?
Using an argument from one Function in a separate function
Can Nikola bootstrap Jinja2 theme render navigation dropdown menu in nikola?
Running Django unittests causes South migrations to duplicate tables
Python - Regex capture multiple fields and build a dictionary with them
Running multiple Python scripts
programatically change matplotlib fill data
Python: include module into one *.py file
TypeError: can't multiply sequence by non-int of type 'tuple'
Assert that two dictionaries are almost equal
How to retry urllib2.urlopen n times
Python: Create a multidimensional array from a loop
MySQL SELECT: Find all languages by Unicode
how to write IS NOT for str.endswith in python [closed]
Python — Use of Numpy.mgrid and Numpy.reshape

Categories

HOME
puzzle
angular-cli
scipy
ncurses
paramiko
formal-verification
google-sheets-api
playframework
hyperledger-fabric
jrebel
tizen-wearable-sdk
sequelize.js
deeplearning4j
metronic
sign
multiple-monitors
datagrip
scala-native
uicollectionview
android-toolbar
quartus
google-api-java-client
zoho
ejbca
clover
uiautomator
hhvm
source-maps
extractor
activepython
hana-studio
blackboard
bxslider
referenceerror
percentage
geo
rhomobile
code-behind
deepstream.io
agent
polyfills
common.logging
stdclass
tripwire
jrules
bing-translator-api
constants
dojox.mobile
crop
rich-text-editor
z3py
bids
automator
recycle-bin
goquery
tiddlywiki
spell-checking
google-maps-ios
in-memory-database
pdfkit
pdflib
iostat
packagemaker
visible
radians
spoofing
contour
mercurial-hook
achievements
amazon-kcl
loopj
schtasks.exe
optionbutton
ffserver
leadtools-sdk
pyopengl
git-checkout
scrollspy
multipleselection
symfony-2.6
io.js
ifft
dvcs
internal
arangodb-php
sanitization
real-time-updates
loop-invariant
nimrod
javascriptmvc
ruboto
html-form-post
qt4.6
linkedhashset
javascriptserializer
feof
fotoware
maven-ant-tasks
entity-framework-ctp5
hinstance
zookeeper
msbuildextensionpack
testunit
noir
dashcode
pivotal-crm
google-instant
filetime
web-statistics
visual-studio-2010-beta-2
virtualquery
economics
configurable

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