Weka Tutorial 3
Weka Tutorial 3
Networks to
predict response
D ENG, Yang
y deng@se.cuhk .edu.hk
Overview
Neural Network has several components including the Input Layer, Hidden Layers
and Output Layer:
(1) Input Layer denotes the input variables that will be fed into the network,
(2) Hidden Layers are the computation layers (or parameters) that will be trained,
(3) Output Layer denotes the output of the model. For example, the class label in
classification task or the real number in regression task.
What is Neural Network?
A typical neural network model can be represented as follow:
What is Neural Network?
As you can see in the figure, each layer contains different number of nodes.
Usually, the number of nodes in input layer will be the number of how many
input variables while the number of nodes in output layer will be the number of
outputs of the model, i.e, number of classes you have in classification.
Activation Function is one of the most powerful cores, which is responsible for
powering Neural Networks. In other words, it decides which neurons will be
activated. Just like our brain, it determines what information would be passed to
further layers.
Without activation functions, the neural networks would not have such a
meaningful representative power.
What is Neural Network?
Sigmoid function, Hyperbolic tangent function and ReLu function are
the activation functions widely used in modern neural network models.
Another core part is the cost function. It is used to calculate loss given the true
and predicted results. The aim of the neural network is to minimize this loss. So
cost function is to evaluate how well is our neural network and effectively drives
the learning of neural network towards its goal.
Some of the most famous cost functions are Cross Entropy, which is used
in classification task, and Mean Square Error, which is used in regression task.
What is Neural Network?
Back to this figure, the network with this structure is called Feed-Forward
network or Multi-layer perceptron.
What is Neural Network?
There are some advanced neural networks with special structure. For example,
the recurrent neural network (RNN) that can be used to handle time-series
(weather of each day) or sequential data (text). Or convolutional neural
network (CNN) that is widely used for handling image.
You can use Weka to easily construct a neural network and it will help you to
configure most of the setting of it like the activation function and cost function.
Again, please
remember to change to CSV data
files(*.csv) in file type.
Preparation for building Neural Network
Now, data is loaded into Explorer.
And then we can perform feature
engineering before building the
Neural Network but this time we
simply use the original dataset to
do it.
Building Neural Network
Click Classify
Building Neural Network
Click Choose
Building Neural Network
Under
classifiers->functions
select MultilayerPerceptron
Building Neural Network
Click on the text near Choose
to access to the configuration
Building Neural Network
Here is the configuration of Multilayer Perceptron.
The default value of HiddenLayers is “a” which means
Weka will help you to setup the hidden layers. You can
also specify how many layer and how many nodes of
each hidden layer. For example, type in 10,5,2 means 3
hidden layers with 10, 5, 2 nodes respectively.
trainingTime means how many iterations we want to
train through. Let set it from 500 to 100.
Then, click OK
Building Neural Network
In the Test options here, we
simply use percentage split 66%
as our testing option.
Building Neural Network
Click Start to start our neural
network construction
Building Neural Network
Since neural network requires much more computation power compared with
decision tree and logistic regression. We need to wait Weka to train our model.
The training time depends on the number of parameters (number of layers and
number of nodes in each layer), number of iterations and number of data we
have.
Viewing the Classifier output
After the training is finished. The
result is shown on the
right panel.
The accuracy of
our model is 88.2889%
Save Neural Network Model
Suppose we want to save the
trained multilayer perceptron
model.
The accuracy of
our model is 66.1%
Make Predictions on New Data
If we want to make prediction
on the new data, instead of
evaluate on certain metrics,
click the More options… to
bring up options for
evaluating the classifier.
Make Predictions on New Data
Uncheck the the following information:
◦ Output model
◦ Output per-class stats
◦ Output confusion matrix
◦ Store predictions for visualization
◦ Collect predictions for evaluation based
on AUROC, etc.
In this case, it gets stuck in a local minimum easily and the optimization algorithm
may think we already reach the global minimum which leads to sub-optimal
results.
Momentum in Neural Network
To avoid this situation, we add a momentum when updating the parameters, which
is a value between 0 and 1 that increases the size of the steps taken towards the
minimum by trying to jump from a local minimum.
Momentum in Neural Network
For more details about the optimization of neural network, you can find out
more recourses in some optimization courses.
Building Neural Network using GUI
Let us investigate more configuration of
the neural network.
Click Start
Building Neural Network using GUI
A GUI window will be shown.
Click OK
Building Neural Network using GUI
After clicking Start, you can see now
your network has 3 hidden layers
where 5 nodes in layer 1, 3 nodes in
layer 2 and 2 nodes in layer 3.
Remarks on Neural Network
The performance of the neural network can be easily affected by the setup of
the hyperparameters. The hyperparameters include the number of hidden
layers, number of nodes, learning rate, momentum, batch size, etc. To achieve a
better performing neural network always requires tons of hyperparameters
tuning. You can play with different hyperparameters setting and investigate
which combination can achieve a better result.