Reputation: 23
I am still learning neural nets and frankly python as well. Here is a basic NN I trained in keras:
from keras.models import Sequential
from keras.layers import Dense
import numpy
# fix random seed for reproducibility
numpy.random.seed(7)
# load pima indians dataset
dataset = numpy.loadtxt("Final_Data.csv", delimiter=",")
# split into input (X) and output (Y) variables
X = dataset[:,0:4]
Y = dataset[:,4]
# create model
model = Sequential()
model.add(Dense(3, input_dim=4, activation='sigmoid'))
model.add(Dense(1, activation='sigmoid'))
# Compile model
model.compile(loss='mean_squared_error', optimizer='sgd', metrics=['accuracy'])
# Fit the model
model.fit(X, Y, epochs=100, batch_size=400)
# evaluate the model
scores = model.evaluate(X, Y)
print("\n%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))
If I want to give my own 4 inputs now to see what the neural net outputs, what will the command look like? I think it is the model.predict command but when I give it 4 inputs within the brackets:
model.predict(0.72804878,0.784146341,0.792682927,0.801219512)
I get back:
TypeError: predict() takes at most 4 arguments (5 given)
Now I am guessing I am totally using the predict command wrong, Any suggestions?
Upvotes: 2
Views: 682
Reputation: 6365
From keras' documentation:
predict(self, x, batch_size=32, verbose=0)
That is why predict
is expecting 4 parameters.
The x
parameter is what you need to specify correctly.
In your case, x
need to be a numpy array of shape (1, 4) that is the number of examples, and the size of each example (the feature vector size).
Try this:
x = np.array([[0.72804878,0.784146341,0.792682927,0.801219512]])
model.predict(x)
Upvotes: 4