I'm using Keras (with Python 3.6) to predict the output of an array (x_test), but I get a TypeError in return.
Here's my code for the prediction:
x_test = [[8],[6],[0],[2],[0],[0],[0],[0],[112.128],[0],[0],[2],[0],[1],[1],[2],[2]]
prediction = model.predict(model, x_test, batch_size = 32, verbose = 1)
And here's the error I get:
TypeError Traceback (most recent call last)
<ipython-input-14-286495dc15a7> in <module>()
1 x_test = [[8],[6],[0],[2],[0],[0],[0],[0],[112.128],[0],[0],[2],[0],[1],[1],[2],[2]]
2
----> 3 prediction = model.predict(model, x_test, batch_size =(17,1), verbose = 1)
TypeError: predict() got multiple values for argument 'batch_size'
If anybody has any advice on what went wrong, any help is greatly appreciated.
For reference, here's my neural network, which seems to work fine.
model = Sequential()
model.add(Dense(32, input_dim=17, init='uniform', activation='relu' ))
model.add(Dense(64, init='uniform', activation='relu'))
model.add(Dense(128, init='uniform', activation='relu'))
model.add(Dense(64, init='uniform', activation='sigmoid'))
model.add(Dense(32, init='uniform', activation='sigmoid'))
model.add(Dense(16, init='uniform', activation='sigmoid'))
model.add(Dense(8, init='uniform', activation='sigmoid'))
model.add(Dense(4, init='uniform', activation='sigmoid'))
model.add(Dense(1, 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=300, validation_split=0.2, batch_size=3)
Many thanks!
You don't need to pass the model argument in model.predict, since the default for predict is predict(self, x, batch_size=32, verbose=0) which model is automatically defined by self.
So your code should just be like:
prediction = model.predict(x_test, batch_size = 32, verbose = 1)
And according to the documentation, x should be a numpy.array not a list.
Arguments:
x: the input data, as a Numpy array.
batch_size: integer.
verbose: verbosity mode, 0 or 1.
Which means that x_test should instead be:
x_test = np.array([[8],[6],[0],[2],[0],[0],[0],[0],[112.128],[0],[0],[2],[0],[1],[1],[2],[2]])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With