Machine Learning Classification Models
Machine Learning Classification Models
Classification Model
Introduction
Classification in machine learning is a predictive modeling process by which
machine learning models use classification algorithms to predict the correct label
for input data.
They spend more time during the training process because of their eagerness to
have a better generalization during the training from learning the weights, but they
require less time to make predictions.
Most machine learning algorithms are eager learners, and below are some
examples:
1. Logistic Regression.
2. Support Vector Machine.
3. Decision Trees.
4. Artificial Neural Networks.
Lazy learners or instance-based learners, on the other hand, do not create any
model immediately from the training data, and this is where the lazy aspect comes
from.
They just memorize the training data, and each time there is a need to make a
prediction, they search for the nearest neighbor from the whole training data,
which makes them very slow during prediction.
1. K-Nearest Neighbor.
2. Case-based reasoning.
Types of classification
Classification-based predictive modeling tasks are distinguished from each other
based on the number of categories and the degree to which the categories are
exclusive:
1. Logistic regression
2. Decision tree
3. Random forest
4. Support vector machine (SVM)
5. K-nearest neighbors
6. Naive Bayes
Classification learning evaluation methods
Some of the most popular evaluation metrics are:
1. Accuracy
2. Precision
3. Recall
4. F1 score
5. Confusion matrix
6. ROC curve
Artificial Neural Network
An artificial neuron is a
mathematical function conceived
as a model of a biological neuron
in a neural network.
Artificial Neural Networks
Artificial Neural Networks contain artificial neurons which are called units .
These units are arranged in a series of layers that together constitute the whole
Artificial Neural Network in a system.
In the majority of neural networks, units are interconnected from one layer to
another.
Each of these connections has weights that determine the influence of one unit on
another unit.
As the data transfers from one unit to another, the neural network learns more and
more about the data which eventually results in an output from the output layer.
Feature Biological Neural Network (BNN) Artificial Neural Network (ANN)
Real neurons with dendrites, cell bodies, Digital units (nodes) that handle numeric weights
Building Block and axons. and activations.
Electrical impulses (action potentials) +
Signal Type chemical transmitters. Numeric values passed between layers.
Local changes in synapse strength (e.g., Data-driven adjustments of weights guided by
Learning Process neurons that fire together wire together). error calculations.
Continuous remodeling of connections Structured training phases that depend on large
Adaptation through growth or pruning (plasticity). datasets and backpropagation.
About 20 watts to run a vast parallel Often requires powerful processors, which can
Energy Use system. draw far more energy.
Can reroute signals if neurons or areas Sensitive to broken nodes unless special
Fault Tolerance are damaged. redundancies are designed.
Distributed across connected neurons; Encoded in numeric weights; may forget old
Memory Storage shaped by daily experiences. tasks when retrained.
Slower signal transfer but extensive Can compute very quickly on specialized
Speed parallelism. hardware, but often in a more linear sequence.
Hard to measure individual neuron Sometimes seen as a “black box” of weights and
Interpretability contributions in complex thoughts. biases.
Activation Functions
Activation functions are an integral building block of neural networks that enable
them to learn complex patterns in data.
They transform the input signal of a node in a neural network into an output signal
that is then passed on to the next layer.
f(x)=ln(1+e^x)
Probit
These are branch-like structures that receive messages from other neurons and allow the
transmission of messages to the cell body.
Cell Body
Each neuron has a cell body with a nucleus, Golgi body, endoplasmic reticulum, mitochondria and
other components.
Axon
Axon is a tube-like structure that carries electrical impulse from the cell body to the axon terminals
that pass the impulse to another neuron.
Synapse
It is the chemical junction between the terminal of one neuron and the dendrites of another neuron.
Neuron Types
Sensory Neurons
The sensory neurons convert signals from the external environment into
corresponding internal stimuli. The sensory inputs activate the sensory neurons and
carry sensory information to the brain and spinal cord. They are pseudounipolar in
structure.
Motor Neurons
These are multipolar and are located in the central nervous system extending their
axons outside the central nervous system. This is the most common type of neuron
and transmits information from the brain to the muscles of the body.
Interneurons
They are multipolar in structure. Their axons connect only to the nearby sensory and
motor neurons. They help in passing signals between two neurons.
The dendrites receive the impulse from the terminal button or synapse of an adjoining
neuron.
Dendrites carry the impulse to the nucleus of the nerve cell which is also called as
soma. Here , the electrical impulse is processed and then passed on to the axon.
The axon is longer branch among the dendrites which carries the impulse from the
soma to the synapse.
The synapse then , passes the impulse to dendrites of the second neuron. Thus, a
complex network of neurons is created in the human brain.
● If the sum of the weighted inputs exceeds the threshold value, then the neuron is said to be activated
and the output signal is 1.
● Otherwise the neuron is not activated and the output signal is 0.
The MCP Neuron, named after Warren McCulloch and Walter Pitts, is a
fundamental concept in the history of artificial neurons and neural networks.
These inputs are weighted equally (all weights set to 1), and the neuron’s output is
determined by applying a weighted sum to its inputs and comparing it to a
threshold.
If the weighted sum is greater than or equal to the threshold, the neuron outputs 1;
otherwise, it outputs 0.
One of the key features of the MCP neuron is its activation threshold. If the
summation of weighted inputs exceeds this threshold, the neuron “fires,”
producing an output signal.
The McCulloch-Pitts Neuron is the first computational model of a neuron. It can be
divided into two parts:
Linear separability (for boolean functions): There exists a line (plane) such that all
inputs which produce a 1 lie on one side of the line (plane) and all inputs which
produce a 0 lie on other side of the line (plane).
Linear Separability
Linear separability, a concept tied to the perceptron model, explores the capability
of a model to separate data points of different classes with a linear boundary.
There exists a line (plane) such that all inputs which produce a 1 lie on one side of
the line (plane) and all inputs which produce a 0 lie on other side of the line
(plane).
Numericals
Characteristics of McCulloch Pitts ANN
Here's a breakdown of its key characteristics:
Threshold Logic:
It sums the weighted inputs and compares the sum to a threshold value. If the sum
exceeds the threshold, the neuron "fires" (output 1); otherwise, it remains inactive
(output 0).
Mimicking Biological Neurons:
The MP neuron aims to capture the essence of how biological neurons function,
by combining multiple inputs and producing a single output based on a threshold.
Foundation of ANNs:
The MP neuron is considered the first computational model of a neuron, laying the
groundwork for more complex artificial neural networks.
Logical Operations:
By adjusting the threshold and weights, the MP neuron can be configured to
perform basic logical operations like AND, OR, and NOT.
Linear Separability:
The MP neuron, in its basic form, is limited to solving linearly separable problems,
meaning it can only separate data points with a straight line or hyperplane.
Classes of Neural Network
There are several different architectures for ANNs, each with their own strengths
and weaknesses. Some of the most common architectures include:
These networks are designed to process data with a grid-like topology, such as images.
The layers consist of convolutional layers, which learn to detect specific features in the
data, and pooling layers, which reduce the spatial dimensions of the data.
Autoencoders:
These are neural networks that are used for generative modeling.
They consist of two parts: a generator that learns to generate new data samples,
and a discriminator that learns to distinguish between real and generated data.
There exist five basic types of neuron connection architecture :
There are no feedback connections in which outputs of the model are fed back
into itself.
Single node with its own feedback
When outputs can be directed back as
inputs to the same layer or preceding
layer nodes, then it results in feedback
networks.
This allows it to exhibit dynamic temporal behavior for a time sequence. Unlike
feedforward neural networks, RNNs can use their internal state (memory) to
process sequences of inputs.
Multilayer recurrent network
In this type of network, processing element output can be directed to the
processing element in the same layer and in the preceding layer forming a
multilayer recurrent network.
They perform the same task for every element of a sequence, with the output
being dependent on the previous computations.
The main feature of a Recurrent Neural Network is its hidden state, which
captures some information about a sequence.
Application of Neural Network
1. Pattern Recognition
2. Image Processing
3. Text recognition
4. Optimization and Constraint satisfaction: Supply Chain Optimization
5. Disease Diagnosis
6. Stock Market Prediction
7. Predictive analytics.
Performance measures of Neural Network
To determine if neural network training is successful, monitor metrics like loss
(training and validation), accuracy, precision, recall, F1-score, and AUC (for binary
classification), and analyze the model's performance on unseen data.
1. Loss (Training and Validation):
Training Loss:
1. This measures how well the model is learning from the training data.
2. It should generally decrease over time as the model learns.
Validation/Test Loss:
AUC measures the model's ability to discriminate between positive and negative
classes, regardless of the classification threshold.
4. Other Important Metrics:
Confusion Matrix:
A table that shows the breakdown of true positives, true negatives, false positives,
and false negatives, providing a detailed view of the model's performance.
For object detection tasks, mAP measures the average precision across different
categories.
For real-time applications, it's important to measure the model's speed and
efficiency (how many predictions can be made per second and how long each
prediction takes).
5. Data Splitting and Evaluation:
Validation Set: Used to monitor the model's performance during training and
prevent overfitting.
Test Set: Used to evaluate the final model's performance on completely unseen
data.
8. Epoch: A single pass of the entire training dataset through an ANN. During one
epoch, forward propagation, backpropagation, and weight updates take place.
9. Batch Size: The number of training examples from the dataset used in a single
iteration of the gradient descent algorithm. In each batch, the weights are updated
based on the average gradient calculated from the examples in the batch.
10. Learning Rate: A hyperparameter that determines the step size or rate at
which the weights are updated during training. It controls the magnitude of weight
adjustments based on the calculated gradient, balancing the speed and accuracy
of learning.
Neural networks, while powerful, have limitations including the need for large
datasets, computational intensity, the "black box" nature of their decision-making,
and potential for overfitting.
1. Data Requirements:
Large Datasets:
Neural networks, especially deep learning models, often require massive amounts
of labeled data to train effectively. This can be a significant hurdle, especially for
tasks with limited or expensive data collection.
Data Quality:
Computational Intensity:
Memory Footprint:
Large neural networks can require significant memory resources, both during
training and deployment.
3. Interpretability (The "Black Box" Problem):
4. Overfitting:
This model can work on non-boolean values where each input connection gets
associated with a weight.
Basic Components of Perceptron
Input Features: The perceptron takes multiple input features, each representing a
characteristic of the input data.
Weights: Each input feature is assigned a weight that determines its influence on
the output. These weights are adjusted during training to find the optimal values.
Summation Function: The perceptron calculates the weighted sum of its inputs,
combining them with their respective weights.
Activation Function: The weighted sum is passed through the Heaviside step
function, comparing it to a threshold to produce a binary output (0 or 1).
Output: The final output is determined by the activation function, often used for
binary classification tasks.
Bias: The bias term helps the perceptron make adjustments independent of the
input, improving its flexibility in learning.
Learning Algorithm: The perceptron adjusts its weights and bias using a learning
algorithm, such as the Perceptron Learning Rule, to minimize prediction errors.
Perceptron Rule of Convergence
Perceptron Learning Rule states that the algorithm would automatically learn the
optimal weight coefficients.
The input features are then multiplied with these weights to determine if a neuron
fires or not.
The Perceptron receives multiple input signals, and if the sum of the input signals
exceeds a certain threshold, it either outputs a signal or does not return an output.
In the context of supervised learning and classification, this can then be used to
predict the class of a sample.
Perceptron Rule of Convergence
The Perceptron rule states that if the data is linearly separable, the Perceptron
algorithm will converge to a solution in a finite number of steps.
Step 2
Step 3
● We apply identity activation functions containing the input layer containing the
input, unit.
●
Step 4
● Else, we have
Step 6:
● We train the network until there is no weight change.
● Thai is called stopping condition for the network, If the conditions is not
satisfied, we start again from Step 4
Perceptron Training Algorithm for Multiple Output Classes
For multiple output classes, the perceptron training algorithm is as follows:
Step 3: Perform Steps 4-6 for each bipolar or binary training vector pair s:t.
Step 5:Calculate output response of each output unit j=1 to m; First the net input is
calculated as:
Then activations are applied over the net input to calculate the output response:
I.e.
else we have
Single-Layer Perceptron:
Structure:
Consists of an input layer and an output layer, with no hidden layers in between.
Function:
Can only learn linear decision boundaries, meaning it can separate data points that
are linearly separable.
Limitations:
Struggles with complex, non-linear data patterns.
Example:
A simple binary classifier that can separate two classes with a straight line.
Multi-Layer Perceptron (MLP):
Structure: Includes an input layer, one or more hidden layers, and an output layer.
Function: Can learn complex, non-linear relationships in data through the use of
hidden layers.
Training: MLPs are trained using algorithms like backpropagation, which adjusts
the weights and biases of the network to minimize errors.
Advantages of Single Layer Perceptrons:
Binary Classification:
They are well-suited for binary classification problems where the data is linearly
separable.
Feature Scaling: Perceptrons can be sensitive to feature scaling, which can impact
their performance.
● Computational Complexity:
○ Training an MLP requires significant computational resources, especially for large networks.
● Prone to Overfitting:
○ Without proper regularization or sufficient data, MLP may memorize the training data instead
of generalizing.
● Black-Box Nature:
○ Understanding how an MLP makes decisions can be challenging due to its complex structure.
● Slow Convergence:
○ Training may require extensive iterations to converge, particularly for deep architectures.
● Need for Hyperparameter Tuning:
○ Performance heavily depends on selecting appropriate learning rates, number of layers, and
neurons.
Limitations of Multilayer Perceptron
Q. Implement AND function using perceptron network for bipolar Inputs and
targets.
Implement OR function with binary inputs and bipolar targets using Perceptron
training algorithm upto 3 epochs.
Find the weights using perceptron network for ANDNOT function when all the
inputs are presented only one time use bipolar input and target.
Adaline Network
● A network with a single linear unit is called Adaline (Adaptive Linear Neural).
● A unit with a linear activation function is called a linear unit.
● In Adaline, there is only one output unit and output values are bipolar (+1,-1).
● Weights between the input unit and output unit are adjustable.
● It uses the delta rule i.e
● Where, , and t are the weight, predicted output, and true value
respectively.
● The learning rule is found to minimize the mean square error between
activation and target values.
● Adaline consists of trainable weights, it compares actual output with
calculated output, and based on error training algorithm is applied.
The differences between the Perceptron and Adaline
Adaptive Linear Neuron Learning algorithm
Step 0: initialize the weights and the bias are set to some random values but not to
zero, also initialize the learning rate α.
Step 2 − perform steps 3-5 for each bipolar training pair s:t.
Here ‘b’ is bias and ‘n’ is the total number of input neurons.
Step 5 Until least mean square is obtained (t - yin), Adjust the weight and bias as
follows −
Step 7 − Test for the stopping condition, if error generated is less then or equal to
specified tolerance then stop.
Multiple Adaptive Linear Neuron (Madaline)
Madaline which stands for Multiple Adaptive Linear Neuron, is a network which
consists of many Adalines in parallel. It will have a single output unit. Some
important points about Madaline are as follows −
● It is just like a multilayer perceptron, where Adaline will act as a hidden unit
between the input and the Madaline layer.
● The weights and the bias between the input and Adaline layers, as in we see
in the Adaline architecture, are adjustable.
● The Adaline and Madaline layers have fixed weights and bias of 1.
● Training can be done with the help of Delta rule.
It consists of “n” units of input layer and “m” units of Adaline layer and “1” unit of
the Madaline layer.
Each neuron in the Adaline and Madaline layers has a bias of excitation “1”.
The Adaline layer is present between the input layer and the Madaline layer; the
Adaline layer is considered as the hidden layer.
Multiple Adaptive Linear Neuron Training Algorithm
Step 0 − initialize the weights and the bias(for easy calculation they can be set to
zero). also initialize the learning rate α(0, α, 1) for simpicity α is set to 1.
Step 2 − perform steps 3-5 for each bipolar training pair s:t
Step 4 − Obtain the net input at each hidden layer, i.e. the Adaline layer with the
following relation −
Here ‘b’ is bias and ‘n’ is the total number of input neurons.
Step 5 − Apply the following activation function to obtain the final output at the
Adaline and the Madaline layer −
The error which is calculated at the output layer, by comparing the target output
and the actual output, will be propagated back towards the input layer.
The main features of Backpropagation are the iterative, recursive and efficient
method through which it calculates the updated weight to improve the network
until it is not able to perform the task for which it is being trained.
Back Propagation Neural will use binary sigmoid activation function. The training
will have the following three phases.
Step 0 − initialize the weights and the bias(For easy calculation and simplicity,
take some small random values but not zero). also initialize the learning rate α(0,
α, 1).
Step 1 − Continue step 2-10 when the stopping condition is not true.
Phase 1
Step 3 − Each input unit receives input signal xi and sends it to the hidden unit for
all i = 1 to n
Step 4 Calculate the net input at the hidden unit using the following relation −
Now calculate the net output by applying the following sigmoidal activation
function
Step 5 Calculate the net input at the output layer unit using the following relation
Calculate the net output by applying the following sigmoidal activation function
Phase 2
Step 6 − Compute the error correcting term, in correspondence with the target
pattern received at each output unit, as follows
Phase 3
Step 8 −
Step 9 −
Step 10 − Check for the stopping condition, which may be either the number of
epochs reached or the target output matches the actual output.
And Function using perceptron