Reputation: 1678
l want to get the accuracy of my model predicting the labels of x_test
from __future__ import print_function
from keras.models import Sequential
from keras.layers import Dense
import keras
import numpy as np
model = Sequential()
model.add(Dense(2000, input_dim=3072, activation='relu'))
model.add(Dense(500, activation='relu'))
model.add(Dense(66, activation='softmax'))
model.fit(x_train,y_train, epochs=100, batch_size=128)
scores = model.evaluate(x_train, y_train)
print("\n%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))
Now l want to get accuracy on prediction
predictions = model.predict(x_test)
l tried :
print("\n%s: %.2f%%" % (model.metrics_names[1], predictions*100))
l got the following error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-262-edbcf292f31c> in <module>()
----> 1 print("\n%s: %.2f%%" % (model.metrics_names[1], predictions*100))
TypeError: float argument required, not numpy.ndarray
Upvotes: 1
Views: 3113
Reputation: 40506
model.predict
produces a numpy.array
which is something completely different from float
. You might try to print that using print(predictions)
but using formatted string with float
absolutely won't work in this case. Try:
print("\n%s:" % (model.metrics_names[1]))
print(100 * predictions)
or
print("\n%s: %s" % (model.metrics_names[1], np.array_str(predictions*100)))
or if you have only one case in x_test
:
print("\n%s: %.2f%%" % (model.metrics_names[1], predictions[0]*100))
Upvotes: 1