Reputation: 3
I want to evaluate my ML model and I am getting this error:
TypeError: cannot unpack non-iterable float object
My code follows:
# mlp for the blobs multi-class classification problem with cross-entropy loss
from sklearn.datasets import make_blobs
from keras.layers import Dense
from keras.models import Sequential
from keras.optimizers import SGD
from tensorflow.keras.utils import to_categorical
from matplotlib import pyplot
# evaluate the model
_, train_acc = model.evaluate(trainX, trainY, verbose=2)
_, test_acc = model.evaluate(testX, testY, verbose=2)
print('Train: %.3f, Test: %.3f' % (train_acc, test_acc))
Upvotes: 0
Views: 1890
Reputation: 4990
It is likely that your model has not accuracy metric, and model.evaluate()
returns only loss. You can check the available metrics like this:
print(model.metrics_names)
And probably it's output is just ['loss']
, and there is not accuracy metric, since you didn't provide it on model.compile()
.
Since it just returns loss, you should change this line like this:
train_loss = model.evaluate(trainX, trainY, verbose=2)
test_loss = model.evaluate(testX, testY, verbose=2)
If you want to get accuracy, you should add it to your model compile:
model.compile(loss='...',metrics=['accuracy'],optimizer='adam')
.
.
train_loss, train_acc = model.evaluate(trainX, trainY, verbose=2)
test_loss, test_acc = model.evaluate(testX, testY, verbose=2)
Upvotes: 0