Deep Evaluation of Model Performance
Introduction
Welcome back! In this lesson, we are taking a deep dive into one of the most important aspects of machine learning: model evaluation. Evaluating your model is like getting the final results of an exam—it tells you how well all your hard work has paid off and where improvements can be made. We will learn how to assess our model's performance using TensorFlow's tools, understand the training dynamics through the history object, and visualize loss data with Matplotlib. By the end of this lesson, you'll be equipped with the skills to confidently evaluate any TensorFlow model, ensuring it performs well on unseen data. Let’s get started!
Deep Dive into Model Evaluation
Evaluation is a crucial step in a machine learning pipeline, as it tells us how well our model performs on unseen data. Performance during training doesn't guarantee real-world success, just like excelling at practice questions doesn't ensure acing the actual test.
Our model was trained using the adam optimizer and categorical_crossentropy loss function. The addition of the accuracy metric during compilation helps quickly gauge performance.
Beware of overfitting, where a model performs well on training data but poorly on test data. Overfitting occurs when a model learns the noise in the training data, negatively impacting its performance on new data. Don't worry; we'll soon learn how to detect it.
Recap: Loading Data and Training the Model
Before we dive into evaluating our model, let's quickly recap the steps we took to load our data and train the model. Here’s the code we used to preprocess our data:
Later on we implemented the following code to train our model on the preprocessed data:
In summary:
- We started by loading the preprocessed data using our custom function
load_preprocessed_data()from a separate file nameddata_preprocessing.pyto obtain our training and testing datasets:X_train,X_test,y_train, andy_test. - We defined a sequential model using TensorFlow's Keras API, with input shapes matching our dataset and various dense layers featuring ReLU and Softmax activations.
- The model was compiled with the Adam optimizer and categorical crossentropy loss function, and we included accuracy as a metric.
- We then trained the model over 150 epochs with a batch size of 5, validating its accuracy and loss on the test data as training progressed.
Now that we are refreshed on the training steps, let's proceed to evaluate how well our model performs.

