AI Lecture 10
AI Lecture 10
INTELLIGENCE
DR. MANAL TANTAWI
ASSOCIATE PROFESSOR
IN
SCIENTIFIC COMPUTING DEPARTMENT
FACULTY OF COMPUTER & INFORMATION
SCIENCES
AIN SHAMS UNIVERSITY
PART 10
➢ K-NN algorithm assumes the similarity between the new data example and
available training data and put the new example into the class that is most like
the available classes.
➢ K-NN algorithm stores all training data and classifies a new data example
based on the similarity. This means when new data example appears then it can
be easily classified into a well suite class by using K-NN algorithm.
K-NEAREST NEIGHBORS (KNN) CLASSIFIER
➢ K-NN algorithm can be used for Regression as well as for Classification but
mostly it is used for the Classification problems.
•Step-3: Among these k neighbors, count the number of the data examples in
each class.
•Step-4: Assign the new example to that class for which the number of the
neighbor is maximum.
SIMILARITY MEASURE
• EUCLIDEAN DISTANCE
EXAMPLE FOR 3-NN
Training data
X1 X2 Y
1 2 A
1 1 A
3 2 B
3 0 A
4 3 B
➢ A very low value for K such as K=1 or K=2, can be noisy and
lead to the effects of outliers in the model.
➢ ADVANTAGES
1) SIMPLE
2) NON-PARAMETRIC
➢ DISADVANTAGES
1) HIGH COMPUTATION OVERHEAD AND TIME CONSUMPTION ESPECIALLY FOR LARGE
DATASETS.
2) HIGH MEMORY USAGE ( SAVING ALL TRAINING DATA)
ARTIFICIAL NEURAL
NETWORKS (ANN)
WHY ANN ?
➢ There are billions of neurons in the brain; Each neuron is connected to some other
neurons (ex: 1000 neurons), creating an incredibly complex network of
communication. Neurons are considered the basic units of the nervous system.
➢ Neuron is the basic working unit of the brain, a specialized cell designed to
transmit information to other nerve cells, muscle, or gland cells.
BRAIN NEURON
➢ Neurons can only be seen using a microscope and
can be split into three parts:
Dendrites — these thin filaments carry information
from other neurons to the soma. They are the “input”
part of the cell.
ANN architectures
➢ Single Layer Perceptron (one output layer, no hidden
layers)
Non-Linear
Linearly
Separable
separable
Single
layer Multi-
Perceptron layer
Perceptron
ARTIFICIAL NEURON
Bias neuron
X0
Ꝋ2
Ꝋ3 Output (Axon)
1
𝑇𝑥 Weights
1 + 𝑒 −𝜃
inputs (Dendrites)
ACTIVATION FUNCTIONS
➢ Activation functions are necessary for neural networks because, without them, the output
of the model would simply be a linear function of the input. In other words, it wouldn’t be
able to handle large volumes of complex data.
➢ Activation functions can generally be classified into three main categories: binary step,
linear, and non-linear, with numerous subcategories, derivatives, variations, and other
calculations now being used in neural networks.
ACTIVATION FUNCTIONS
➢ Binary step is the simplest type of activation function, where the output is binary based
on whether the input is above or below a certain threshold. Linear functions are also
relatively simple, where the output is proportional to the input. Non-linear functions are
more complex and introduce non-linearity into the model, such as Sigmoid ,Tanh, Softmax
and Rectified Linear Unit (ReLU) (used in deep learning models).
➢ The non-linear activation functions are the commonly used and enable the neural network
by their nonlinearity to model more complex functions within every node, which enables
the neural network to learn more effectively.
ACTIVATION FUNCTIONS
RELU Function
Sigmoid Function Tanh (hyperbolic) Function (Deep Learning)
ACTIVATION FUNCTIONS
➢ SoftMax function is used in the neurons of outer layer of multiclass network.
➢ It turns logits value into probabilities by taking the exponents of each output
and then normalizing each number by the sum of those exponents so that the
entire output vector adds up to one. Logits are the raw score values
produced by the last layer of the neural network before applying any
activation function on it.
if we vary the values of the weights Ꝋs, keeping bias if we vary the values of the weight Ꝋs, and vary the
‘Ꝋ0’=0, we will get the above graph value of bias ‘Ꝋ0’, we will get the above graph
ARTIFICIAL NEURON (SECOND VISIT)
Bias neuron
X0
Ꝋ2
Ꝋ3 Output (Axon)
1
𝑇𝑥 Weights
1 + 𝑒 −𝜃
inputs (Dendrites)
ANN ARCHITECTURES
-30
20
20
Y
0
0
ℎ𝜃 𝑥 = 𝑔( −30 𝑋0 + 20𝑋1 + 20 𝑋2 ) 0
1
OR FUNCTION
-10
20
20
Y
0
1
ℎ𝜃 𝑥 = 𝑔( −10 𝑋0 + 20𝑋1 + 20 𝑋2 ) 1
1
To be continued …..
CREDIT FOR