Icon

01_​Iris_​Classification_​ANN_​Solution

Classifying the iris dataset with ANN 4-3-1

Exercise of the L4-DL Deep Learning Specialization course.

The goal is to train a multilayer Perceptron with 4-8-3 layers, using BackPropagation, to classify the Iris dataset.

URL: L4-DL course slides https://www.knime.com/form/material-download-registration

Step 2. Keras Architecture

  1. The first (input) layer with a Keras Input Layer node with 4 units (Shape), corresponding to the input features

  2. The second (hidden) layer with a Keras Dense Layer node, with 8 units and the ReLU activation function (Activation function)

  3. The last (output) layer with a Keras Dense Layer node, with 3 units and the Softmax activation function



Step 1. Data Preparation & Partition

The Data Preparation & Partition metanode preprocesses and partitions data (75% training, 25% testing). The target is coded numerically as 1, 2, and 3, corresponding to setosa, virginica and versicolor, respectively.



Session 1 - Classical Neural Networks

Exercise 01 Iris Classification ANN

Learning objective: In this exercise, you'll learn how to train a multilayer perceptron with 4 input neurons, a hidden layer with 8 neurons, and an output layer with 3 neurons, using Backpropagation, to classify the Iris dataset.


Workflow description: The iris dataset contains 4 numerical features (sepal length, sepal width, petal length, & petal width). Our goal is to use these features to classify irises into 3 categories (setosa, versicolor, & virginica). We do so by creating a Keras network model with 3 layers, with 4-8-3 units.


You'll find the instructions to the exercises in the yellow annotations.

Step 3. Train the Keras network with a Keras Network Learner node

  1. Connect the network output port (red square) of the output node of your network to the network input node (red square) of the Keras Network Learner node. Connect the training set to the input port (black triangle)

  2. Under the Input Data tab, the Conversion is From Number (double). The four numerical features should be used as the input

  3. Under the Target Data tab, the Conversion is From Collection of Number (integer) to One-Hot Tensor, with class_collection as the Target column.

  4. Under Options tab, set Epochs to 100, and Training batch size to 5.


    Note: Do not change the loss function (Categorical cross entropy) or the Optimizer (Adam)



Step 4. Apply the trained network model to the testing data with a Keras Network Executor node

  1. Connect the network output from the Learner node to the Executor node, as well as the training set from the metanode

  2. Check Keep input columns in output table

  3. As for the Inputs, the Conversion is From Number (double), with the 4 numeric input features

  4. For the Outputs, click on the add output button. The network output layer is selected by default. The Conversion is To Number (double). The Output column prefix are appended to the output column names



Step 5. Convert the network output to a categorical variable

The three output columns generated by the network model represent the class probabilities for three categories. The columns are in the order of 0: setosa, 1: virginica, and 2: versicolor. The predicted class is the one with the highest probability among the three. Use an Expression node to create a column with the predicted class.

Finally transform the long into an integer by using a Number Rounder node.



Step 6. Assess the prediction accuracy using a Scorer node

Compare the target column vs. the prediction from the network



input layer 4 units
Keras Input Layer
Train thenetwork100 epochsBatch size 5Adam optimizer
Keras Network Learner
Transform class to integer Partition 75% - 25% Normalization
Data Preparation & Partition
Extract prediction
Expression
hidden layer 8 units ReLU
Keras Dense Layer
Number Rounder
Read the iris dataset
Table Reader
Apply trained network
Keras Network Executor
Examine theaccuracy
Scorer
output layer 3 unit Softmax
Keras Dense Layer

Nodes

Extensions

Links