I have the following neural network structure:
model = tf.keras.Sequential([
tf.keras.Input(shape=(15, )),
tf.keras.layers.Dense(13, activation=tf.keras.layers.LeakyReLU(alpha=0.001)),
tf.keras.layers.Dense(12, activation='softmax')
])
model.compile(loss = 'SparseCategoricalCrossentropy', optimizer='nadam', metrics=['accuracy'])
This code is working for model.fit
and I have the accuracy for the test set with no problem, but I'm trying to insert a specific example to "see" the softmax possibilities for it.
I'm inserting this:
test = [5154385, 13.85, 16525, 15414, 15405, 882.0, 60 ,15274.86, 15274.86, 0, 0, 0, 12, 0]
test = np.array(test)
model.evaluate(test, list_of_12_possibilites)
Each line of example of my dataset is composed by 14 columns and should be splitted into 12 different possibilites (the 15th value in my input layer is the label used to train). So, this is my desired output:
possibility_1: 0.0058
possibility_2: 0.0009
possibility_3: 0.0148
....
possibility_12: 0.002
But I'm getting the following error:
ValueError: Data cardinality is ambiguous:
x sizes: 14
y sizes: 12
Make sure all arrays contain the same number of samples.
CodePudding user response:
As the guys stated in the comments, I was using the wrong function. Instead of model.evaluate()
I should use model.predict()
.
So the following code is correct now:
predictions = model.predict(test, batch_size=128)