
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
model.fit(x_train, y_train, epochs=1000)
Fitting and compilation for the RNN generate a complete model. This procedure is quite slow. It can take few
seconds up to days, depending on the model complexity and the training dataset size.
For the AI-car sensing node, set 1000 epochs and 60% of the available window waveform used for the training.
This results in a computation time of around 70 seconds.
Figure 10.
Complete model generation
2.4.4
Model evaluation
To evaluate the model accuracy, choose a holdout window waveform. This should be based on data not used in
the training process, to get an unbiased estimation of the model performance when making a prediction on “new”
data.
The model evaluation speed is proportional to the amount of data used for it, but faster than the training phase.
A confusion matrix performs the model accuracy evaluation. This is a technique to summarize the algorithm
classification performance. As the datasets have different sizes, using a pure classification accuracy could be
misleading. Therefore, calculating a confusion matrix can give you a better idea of what your classification model
is getting right and what miss classification is obtaining.
Use the following code to build a confusion matrix.
Y_pred = model.predict(x_test)
y_pred = np.argmax(Y_pred, axis=1)
confusion_matrix = tf.math.confusion_matrix(y_test, y_pred)
plt.figure()
sns.heatmap(confusion_matrix,
annot=True,
xticklabels=Y_LABELS,
yticklabels=Y_LABELS,
cmap=plt.cm.Blues,
fmt='d', cbar=False)
plt.tight_layout()
plt.ylabel('True label')
plt.xlabel('Predicted label')
plt.show()
The confusion matrix for the AI-car sensing node is:
•
26 actual parking window waveforms used for the evaluation have been predicted as parking (no miss
classifications).
UM3053
AI-car sensing node life cycle
UM3053
-
Rev 1
page 12/39