Icon

01_​Training_​Solution

01_Training

In this exercise you will create a simple Feedforward Neural Network to predict the income class of a person in the adult dataset. The steps are:
- Define a suitable model structure
- Preprocess the data
- Train the model
- Apply the model to the test set and evaluate the result
- Export the trained network

URL: KNIME Deep Learning Integration https://docs.knime.com/2020-07/deep_learning_installation_guide/index.html#keras-integration
URL: Guide to Intelligent Data Science https://www.datascienceguide.org/

Read and preprocess the data - Read the adult.csv dataset. Drag and drop it from the data folder and get familiar with it. It contains personal information such as education, workclass, income, marital status of about 30K people. Most of the columns contain categorical values (Self-employed, Divorced etc.. ). We need to one-hot encode these information into numbers in order to use them in our FFNN. - Drag and drop the Attribute Encoder shared component from the Exercise folder. It will perform the index-based encoding of the categorical attributes. In order to train the network, we need to split the dataset into train, validation and test set. - Drag and drop the Dataset Preprocessing shared component from the Exercise folder. It is already configured to split the dataset using stratified sampling and apply Gaussian normalization and to index-encode the target variable.
Define the structure of your FFNN using the Keras Layers nodes. A possible solution can be: - Input Layer node configured for 13 inputs - Two Dense Layers with 6 units and ReLu activation function - A Dense Layer with Sigmoid activation function producing one output Tip: use the Name prefix
Create a Keras Feedforward Neural Network to solve a binary classification problem. Train the network with the Adult dataset to predict the income attribute of a person. The income attribute has two possible values: <=50K or >50K.
Notice that Deep Learning in KNIME comes with the Keras integration. You have to set up a Python environment with Keras and install the Keras Integration for KNIME. Refer to this guide for more information: https://docs.knime.com/2020-07/deep_learning_installation_guide/index.html#keras-integration
Deployment Add a Keras Network Writer node. Connect it to the model output of the Keras Network Learner. Execute it to export the trained network as *.h5 file
Apply trained network and extract predictions - Add a Keras Network Learner node that takes in input the train and the validation sets (first and second output of the Data Preprocessing component). Connect the last layer of the network structure previously defined. Open the configuration window. - Use all but the income column as Input Data - Select only the income column as Target Data - Select Binary cross entropy as loss function (Target Data Tab) - In the Options tab select an optimizer (e.g. Adam) and the number of epochs (e.g. 20) - Apply the model to the test set using the Keras Network Executor node - Check the box to keep input columns in the output table - Click on "add output" and select the last layer of your model - Add a Rule engine node. Write a rule that converts the network output (decimal values between 0 and 1) back into category values of the income column (either <=50K or >50K). - Choose the output column from the Column list. - If the value of this column is <0.5, output is "<=50K". Otherwise it is ">50K" - Append these converted values in a new column "prediction" - Evaluate the performance of the model using a Scorer node. Select the columns income and predicion OPTIONAL: Add a Dropout layer to your model and train it again. Did the performance improve?
13 inputs
Keras Input Layer
6 units
Keras Dense Layer
6 units
Keras Dense Layer
1 unit
Keras Dense Layer
Train the model Optimizer: Adam Epochs: 20
Keras Network Learner
evaluate performance
Scorer
Apply the model to the test set
Keras Network Executor
convert output
Rule Engine
Keras Dropout Layer
Export trained model
Keras Network Writer
index-based encoding of categorical variables
Attribute Encoder
Read adult.csv
CSV Reader
partitioning & Normalization & target encoding
Dataset Preprocessing

Nodes

Extensions

Links