Building a Multi-Class Classification Model with TensorFlow
Lesson Overview
Hello, there! You have done a fantastic job with preprocessing the Iris dataset. Now, it's time to apply what you've learned by building a multi-class classification model using TensorFlow. We will guide you through each step of constructing and training this model specifically for our problem. We'll also unpack the history object returned by the model's training process. You're in good hands. Let's get started.
Loading the Preprocessed Dataset
Before we start building our multi-class classification model, we need to load our preprocessed dataset. To maintain modular code, we use the load_preprocessed_data function from our previous lesson, stored in data_preprocessing.py. This function handles loading, splitting, scaling, and one-hot encoding the Iris dataset, providing the data in a format that is ready to train our model.
Load the preprocessed dataset:
Here's a brief recap of the data_preprocessing.py:
With the dataset loaded, we're ready to build our multi-class classification model.
Building the Model
The next step is building our multi-class classification model. TensorFlow makes it easy for us to construct models using the Sequential API which allows us to create models layer-by-layer.
Our input shape aligns with the four features (sepal length, sepal width, petal length, petal width) in our Iris dataset. The model includes two dense layers, each having 10 neurons and ReLU (Rectified Linear Unit) as the activation function, which will help us introduce non-linearity into our model. Finally, we have an output layer with three neurons representing our three Iris species.
Our output layer uses the softmax activation function, which helps in multi-class classification problems by converting the raw output scores (logits) into probabilities. Softmax takes the output of each neuron and turns it into a probability between 0 and 1, with all probabilities adding up to 100%. Essentially, it tells us the likelihood that the input data point belongs to each of the three classes (Iris species) we have in our dataset. The class with the highest probability is selected as the model's prediction.
