SoftComputing
SoftComputing
https://www.javatpoint.com/single-layer-perceptron-in-tensorflow
https://www.datasciencecentral.com/learning-rules-in-neural-network/
https://towardsdatascience.com/understanding-backpropagation-algorithm-
7bb3aa2f95fd
https://www.slideshare.net/AMITKUMAR4132/fuzzy-set-theory
https://www.educba.com/what-is-genetic-algorithm/
Here function x is doing computing process which we can say this function F
Formal Method / Algorithm / Mapping Function
Here in picture we can say that we get desired output in consequent which is
done by control Action
Features of Soft Computing
• Precise Solution
• Unambiguous & Accurate
• Mathematical Model
Precise Solution
If we use computing and does problem solving then it should be precise
manner
Unambiguous & Accurate
As we have mentioned computing unit which transforms data from function
that is nothing but which is algorithm
And algorithms process the data by control action
So control action should be unambiguous and algorithm should not be two
meaning
Mathematical
This is also algorithm to solve the problem
Soft Computing Technique
Computation is a process of converting the input of one form to some other
desired output form using certain control actions. According to the concept of
computation, the input is called an antecedent and the output is called the
consequent. A mapping function converts the input of one form to another
form of desired output using certain control actions. The computing concept is
mainly applicable to computer science engineering. There are two types of
computing, hard computing, and soft computing.
Hard Computing
• Precise Results
Hard computing is a process in which we program the computer to solve
certain problems using mathematical algorithms that already exist, which
provides a precise output value. One of the fundamental examples of hard
computing is a numerical problem.
This will be precise manner because in Hard computing allows mathematical
operation to solve algorithm which exists on the method
• Control Action
• Unambiguous Data
Control action allows the mathematical operation which performs on
algorithm
Quick sort
Bubble Sort
Merge sort
Insertion Sort
Heap sort
Selection
Computational Geometry Problem
In mathematics Graph x and y coordinate
Imprecision
Dynamic -> The result may change in the output because what algorithm
size is changes that is not adaptive
Uncertainty
When programmer runs any program then it is not the same data as user
wants because user also apply implementation in different manner
Because lack of service and when we use the hard computing that is High
Solution Cost due precise and unambiguous method
Example 2
Problem 1
Are string1 and string2 same?
No, the solution is simply No. It does not require any algorithm to analyse
this.
Let's modify the problem a bit.
Problem 2
How much string1 and string2 are same?
Solution
Through conventional programming, either the answer is Yes or No. But
these strings might be 80% similar according to soft computing.
You have noticed that soft computing gave us the approximate solution.
Fuzzy Set Crisp Set
It specifies a number
It specifies the value as either 0
Value between 0 and 1, which
or 1.
includes both 0 and 1.
Neural networks were developed in the 1950s, which helped soft computing
to solve real-world problems, which a computer cannot do itself. We all know
that a human brain can easily describe real-world conditions, but a computer
cannot
• Layers
• Connections
• Activation Function
Neurons
Neurons is like Human Brain what we think and gives the output Neuron Is Just
Like Store the data
Data is stored and it will calculating the data now it is creating Layer when its
processing the data
Connection
Activation Function
Output becomes sigmear data but we want that our value should come in None
Linear Data between (0 & 1) then apply Activation function
Over all the in above picture we are doing input as training data and it gives
relevant data as we want because in every layer Data is relating as desired
output
Example
Soft computing deals with the approximation model. You will understand
with the help of examples of how it deals with the approximation model.
Let's consider a problem that actually does not have any solution via
traditional computing, but soft computing gives the approximate solution.
Advantages
The benefits of soft computing are
• The simple mathematical calculation is performed
• Good efficiency
• Applicable in real-time
• Based on human reasoning.
Disadvantages
The disadvantages of soft computing are
• It gives an approximate output value
• If a small error occurs the entire system stops working, to overcome its
entire system must be corrected from the beginning, which is time
taking process.
Applications
The following are the applications of soft computing
• Controls motors like induction motor, DC servo motor automatically
• Power plants can be controlled using an intelligent control system
• In image processing, the given input can be of any form, either image or
video which be manipulated using soft computing to get an exact
duplicate of the original image or video.
• In biomedical applications where it is closely related to biology and
medicine, soft computing techniques can be used to solve biomedical
problems like diagnosis, monitoring, treatment, and therapy.
Computing is a technique used to convert particular input using control
action to the desired output. There are two types of computing
techniques hard computing and soft computing. Here in our article, we
are mainly focusing on soft computing, its techniques like fuzzy logic,
artificial neural network, genetic algorithm, comparison between hard
computing and soft computing, soft computing techniques, applications,
and advantages. Here is the question “How are soft computing is
applicable in the medical field?”
Fuzzy Logic
+
+
There are three types of soft computing techniques which include the
following.
• Fuzzy Logic
• Artificial Neural Network
• Genetic algorithm
Example of Fuzzy Logic as comparing to Boolean Logic
Neural networks were developed in the 1950s, which helped soft computing
to solve real-world problems, which a computer cannot do itself. We all know
that a human brain can easily describe real-world conditions, but a computer
cannot
Here Neural Means Neuron and Network which is connected in them self
Neurons is like Human Brain what we think and gives the output Neuron Is Just
Like Store the data
Fuzzy Set
Membership Belong
U (meun)
U = {1, 2, 3, 4, 5 }
S = {1, 2}
={(1,1) (2,1),(3,0),(4,0),(,5,0)}
x,u
Fuzzy set theory, introduced by Lotfi A. Zadeh, redefines the conventional notion
of set theory by accommodating the granularity of membership within a set.
Unlike classical set theory, which employs binary membership functions, fuzzy sets
allow for a continuum of membership grades, thereby enabling the representation
of partial truths.
Fuzzy Logic
Means values will come between in 0 and 1 like 0.2, 0.3, 0.1
Membership function
And we have to find out whether this sub set belong to U means S
value belongs to Universal set U
={1,1} 1 contains in U set Yes then 1 here U=1->x and 1 Yes 1 -> µ
(meun) then its membership value is 1
{(1,1),(2,1),(3,0),(4,0),(5,0)}
It denotes Degree
Fuzzy Set
A = {(x, µA (x)}
X = {1,2,3,4,5,6,7}
A->number closed to 3
or operation in Boolean
x µ
A = {(10, 0.2), (20, 0.4), (25,0.7), (30,0.9), (40,1)}
B = {(10,0.4), (20, 0.1), (25,0.9),(30, 0.2), (40,0.6)}
key=[]
k=0
for i in range(5):
k+=10
key.append(k)
print("Set Value : ",key)
i=0
µc=[]
x=[0.8,0.3,0.4,0.6,0.2]
y=[0.5,0.7,0.9,0.1,0.3]
while i < len(x):
if x[i] > y[i]:
µc.append(x[i])
elif y[i] > x[i]:
µc.append(y[i])
i+=1
print(µc)
bold=dict(zip(key,µc))
print(bold)
Output :
Set Value : [10, 20, 30, 40, 50]
[0.8, 0.7, 0.9, 0.6, 0.3]
{10: 0.8, 20: 0.7, 30: 0.9, 40: 0.6, 50: 0.3}
Solution :
import random
num=int(input("Enter the size of Element in set.."))
if num > 5:
print("Enter size 5 ")
else:
b=[]
h=[]
j=0
for n in range(num):
t=random.uniform(0,1)
g=round(t,1)
b.append(g)
print("membership : =",b)
if num > 5:
print("Enter size 5")
else:
c=[]
k=0
for m in range(num):
k+=10
c.append(k)
print("Set Value : ",c)
print("\n")
i=0
µA=list()
while i < len(c):
t=1-b[i]
s=round(t,2)
µA.append(s)
i+=1
print(µA)
comp=dict(zip(c,µA))
print("Fuzzy Complement ")
print(comp)
Output :
Enter the size of Element in set..4
membership : = [0.9, 0.8, 0.8, 0.2]
Set Value : [10, 20, 30, 40]
Here first Add both A and B µ Value and arrange Minimum Value also check
from 1 if the µ vaalue is greater than 1 then place 1 µ value [0 – 1]
x µ
A = {(10, 0.2), (20, 0.4), (25,0.7), (30,0.9), (40,1)}
B = {(10,0.4), (20, 0.1), (25,0.9),(30, 0.2), (40,0.6)}
= (10, 0)
= (30,0.9) and (30,0.2) again (0.9+0.2) = 1.1 – 1 = 0.1 and compare to 0 then
maximum value is 0.1 (30,0.1)
Product
Ex : Dictionary :
value=[0.2,0.8,0.1,0.6]
print(dict(zip(key,value)))
Ex :
dicts = {}
keys = range(4)
values =[0.2,0.8,0.1,0.6]
for i in keys:
dicts[i] = values[i]
print(dicts)
Output :
A = {a, e, i, o, u}
B = (1,3,5,7,9}
The elements in roster form can be in any order (they don't need to be in
ascending/descending order).
The elements should not be repeated in set roster notation.
One of the limitations of roster notation is that we cannot represent a large number
of data in roster form.
if we want to represent the first 100 or 200 natural number in a set B the limitation
we can be overcome by representing data with the help of a dotted line. then it is
necessary to represent large data i.e, odd number between 1 to 100
{1,3,5,7,……….,199}
Builder Notation
Such that’ is expressed by the symbols ‘|’ (a vertical bar separator) or ‘:’ (colon).
the set {1,3,5,7,9} is written as A = {x | x ∈ ℕ, 1 < x < 10, x is odd} and is read as
"set A is the set of all ‘x’ such that ‘x’ is a odd number between 1 and 10."
A = {x | x ∈ ℕ, 5 < x < 10} and is read as "set A is the set of all ‘x’ such that ‘x’ is
a natural number between 5 and 10."
Real Number :-> union of rational number and irrational number, these number can
be expressed on a number line
A set of real numbers less than 8 is written in set builder notation as follows:
Types of Set
Singleton Set
S = {10}
Therefore the five singleton sets which are subsets of the given set A is {1}, {3}, {5},
{7}, {11}.
Example :
Disjoint Set
Disjoint
In order to find if two sets are disjoint sets, we need to perform the intersection of
sets operation on these two sets. The condition for any given sets to be disjoint can
be given as A ∩ B = 𝛟
P = {1, 2}, Q = {2, 3} and R = {5, 3}.
P ∩ Q = {1, 2} ∩ {2, 3}
And,
P ∩ R = {1, 2} ∩ {5, 3}
P∩R=𝛟
Example in Python
p = {1, 2}
q = {2, 3}
r = {5, 3}
res = p.intersection(q, r)
print(res)
Output :
set()
Example :
p = {1, 2,1,4,6}
q = {2,3,4,6}
r = {5,4,3}
s = {4,9,12,16}
m = p.intersection(q)
print(m)
n = q.intersection(r)
print(n)
t = p.intersection(q,r,s) // p ∩ q ∩ r ∩ s
print(t)
Output :
{4}
So, among the given sets, P and R can be considered as disjoint sets.
Disjoint sets:
Two sets A and B are said to be disjoint, if they do not have any common element
in them, i.e. A ∩ B = { }. For sets
Finite set
Finite sets can be easily represented in roster notation form. For example, the set
of vowels in English alphabets, Set A = {a, e, i, o, u}
Infinite set
Here x such that x is a integer and x is greater than 10 i.e, 11,12,13,………. infinite
no.
Here x is a integer and x is greater than 7 and less than 8, so there is no number
which is greater than 7, and less than 8 means it contains 0 no. element
Subset
Empty set is subset of every set and Every set is subset of itself
ɸ, {1}, {2}, {3}, {1,2},{1,3}, {2,3}, {1,2,3} Now Here total no. of Subset is 8
Here we can say if any set have nth element then the total no. of subset will be 2n
and
Subsets are
- classified as
Proper Subset
Improper Subsets
A proper subset is denoted by ⊂ and is read as ‘is a proper subset of’. Using this
symbol, we can express a proper subset for set A and set B as;
A⊂B
Example: If set A has elements as {12, 24} and set B has elements as {12, 24, 36},
then set A is the proper subset of B because 36 is not present in the set A.
A⊂B
But A = B
Ex: : if A = { 1,2,3 }
proper subset = ɸ, {1}, {2}, {3}, {1,2},{1,3}, {2,3} and Improper set is {1,2,3}
: if A { 1,2,3 }
The subsets of any set consists of all possible sets including its elements and the
null set. Let us understand with the help of an example.
Subsets =
{}
{1,2,3,4},
{1,5,7,9}
if A = {2,4,6}
Number of subsets: {2}, {4}, {6}, {2,4}, {4,6}, {2,6}, {2,4,6} and Φ or {}.
itertools.combinations():
Here is a simple program to showcase the different iterators that can be used.
s = {1, 2, 3}
k=2
Example :
x = ['A', 'B', 'C', 'D']
result = list(map(set, itertools.combinations(x, 2)))
print(list(result))
Output :
[{'A', 'B'}, {'C', 'A'}, {'D', 'A'}, {'C', 'B'}, {'D', 'B'}, {'D', 'C'}]
Example :
import itertools
s = {1, 2, 3}
n=2
print(findsubsets(s, n))
Output:
[(1, 2), (1, 3), (2, 3)]
Example
set1=[1,2,3]
subs=getsubset(set1)
print(list(map(set,subs)))
Output:
[set(), {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}]
Output:
0
01
012
0123
Improper Subset
A=B
Improper Proper
⊆ ⊂
A=B
Fuzzy Set
Union
Fuzzy Set
Example
Fuzzy Sets (Continue)
• Let A be the fuzzy set of "smart" students, where "smart" is fuzzy term.
A = {1, 2, 3},
B = {2, 3, 4},
C = {5, 6}
Commutativity :-
(A ∪ B) = (B ∪ A) A ∪ B = {1, 2, 3, 4} → LHS
(A ∩ B) = (B ∩ A) B ∪ A = {1, 2, 3, 4} → RHS
A ∩ B = {2, 3} → LHS
B ∩ A = {2, 3} → RHS
Associativity :- A ∪ B = {1, 2, 3, 4}
(A ∪ B) ∪ C={1, 2, 3, 4, 5, 6}
(A ∪ B) ∪ C = A ∪ (B ∪ C) B ∪ C = {2, 3, 4, 5, 6}
(A ∩ B) ∩ C = A ∩ (B ∩ C) A ∪ (B ∪ C) = {1, 2, 3, 4, 5, 6} → RHS
A ∩ B = {2, 3}
(A ∩ B) ∩ C = ϕ → LHS
B∩C=ϕ
A ∩ (B ∩ C) = ϕ → RHS
Distributivity :- A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C)
B∩C=ϕ
A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C) A ∪ (B ∩ C) = {1, 2, 3}→LHS
A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) A ∪ B = {1, 2, 3, 4}
A = {1, 2, 3}, A ∪ C = {1, 2, 3, 5, 6}
(A ∪ B) ∩ (A ∪ C) = {1, 2, 3} → RHS
B = {2, 3, 4},
A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)
C = {5, 6} B ∪ C = {2, 3, 4, 5, 6}
A ∩ (B ∪ C) = {2, 3} → LHS
A ∩ B = {2, 3}
A∩C=ϕ
(A ∩ B) ∪ (A ∩ C) = {2, 3} → RHS
A∩A=A
A ∪ A = {1, 2, 3} = A
A ∪ X = {1, 2, 3, 4, 5, 6} = X
A ∩ X = {1, 2, 3} = A
A ∪ ϕ = {1, 2, 3} = A
A∩ϕ={}=ϕ
Transitivity :-
If A ⊆ B, B ⊆ C, then A ⊆ C
Involution :-
(Ac)c = A
µ = {1,2,3,4,5}
A={2,3}
Ac = µ - A = {1,4,5}
L.H.S. (Ac)c => {1,2,3,4,5} – {1,4,5} = {2,3}
Example
µ = {a,b,c,d}
A={a,b}
(Ac)c = A
Set is one of 4 built-in data types in Python used to store collections of data, the
other 3 are List, Tuple, and Dictionary, all with different qualities and usage.
* Note: Set items are un changeable, but you can remove items and add new
items.
Union
Output :
{1, 2, 'a', 3, 5.2, 'b', 'c'}
Example
set1 = {"a", "b" , "c",5.2}
0set2 = {1, 2, 3}
set1.update(set2)
print(set1)
Output:
{1, 2, 3, 'b', 5.2, 'c', 'a'}
typecast into set
x=["ab",4,9,12,3.5,12,9.2]
m=set(x)
print(m)
output :
{3.5, 4, 9, 9.2, 12, 'ab'}
Subset
a={1,2,3,}
b={1,2,3,4}
print(a.issubset(b))
Output:
True
Intersection
a={3,6,0,7.6,"a",1,False,15}
b={1,3,6,9,12,15,0}
z=a.intersection(b)
print(z)
output :
{0, 1, 3, 6, 15}
print(check_list)
print("\n")
result = set(l1)
for s in check_list:
result = result.intersection(s)
print(result)
output :
[{'three', 'one', 'six'}, {'four', 'one', 'five'}, {'three', 'five', 'one'}]
{'one'}
Fuzzy to Crisp Conversion
Centroid method
Let take an example by taking the union of two fuzzy set so in this diagram two
axis y is µ membership value and x axis and defuzzified value received by
centeroid two fuzzy set the centroid value in between two fuzzy set
Here centroid value is Z* which Gives the z point which is located
defuzzified value and here A~ is fuzzy at the center of gravity
set value
Let take another example
Here Set 3 is the union of two fuzzy set set1 and set 2
Syllabus
Unit - 1
• Neurons (Nodes)
• Layers
• Connections
• Activation Function
Data is stored and it will calculating the data now it is creating Layets when its
processing the data
Connection
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.
An activation function in a neural network determines which neurons are
activated as information moves through the network's layers. It's a key
component of neural networks that allows them to learn complex patterns in
data.
Neural Network
A neural network is a machine learning technique that uses a network of
interconnected nodes to process data and learn from mistakes,
For example Internet : Sharing the Data
If we talk about human brain there are high number of neurons
neurone,[ HYPERLINK "https://en.wikipedia.org/wiki/Neuron"1 HYPERLINK "https://en.wikipedia.org/wiki/Neuron"] or nerve cell which are
connected
There are gazillions of Neurons in Human Brain which are connected with
network and that connectivity provides the flow information and process it
and parallel process
In Human Brain can learning algorithm from experience and train the data in
itself and the capacity of training and learning make the human brain a very
important organ
And we do in artificial machine we want to implement brain like human brain
which we can say neuron network and that we can say Artificial Neural
Network which works the learn the algorithm and train the data
For Example, First day you go to the office then you recognize the faces of
people and staff on there and some have less hair shaved or trim detect the
faces next again you go to office then you’ll detect the face and recognize the
faces so many people may have shaved or trimmed But you will recognize
them.
Human brain learns and trains But the same thing if we do in Normal
Computer then it’ll have to do all the scanning if there are 100 people. You’ll
have to scan their photos and give them to the computer. If you check again
the next day
So the Normal computer can work only the base of algorithm which gives the
output like recognize the face expression of any actor
If we implement this with the help of Neural Network, then it recognizes 90%
so here the accuracy is increasing this is the power of Learning algorithm
Here nodes are connected with some weight and other layer nodes are
connected here with the help of activation function we can apply
corresponding input get the output
Let’s assume we have input x1, x2, x3 all will be connected and
rest of the layer will be connection completely after that we get
Output
4 Feedback ANN
Feedback is provided to adjust parameters
Here parameter return back towards first layer if any error occurs then
parameter can be updated and because to minimize
Non Linear Separable Data
Example 2
7, 7=> 1 (Pass),
Y =x1.w1 + x2.w2 + b
Here b (bias) value will update as much as update then value will be
fluctuating it.
So at initial level we have train the data giving the value of w1 and w2 and
updated it so that loss should be minimal
this is sigmoid function
w1=0.5
w2=-0.3
b1=0.1
Now check formula: Y =x1.w1 + x2.w2 + b1 let’s take new data for the training
the data
1
-2.4
0.1
-1.3
Here -1.3 value comes after using activation function now put this in sigmoid
function and value
1/1+(e^-(-1.3)) = 1/4.67 => 0.21 means it’s the probability near fail
Lets say we take x1= 6 and x2 = 7 in activation function
Y =x1.w1 + x2.w2 + b1
= 6*0.5 + 7* -0.3 + 0.1 = 1
x1 x2 Total
6 7 0.1
0.5 -0.3
3 -2.1 0.1 1
0.9 0.1 1
FFN RNN
Forward neural network which is going forward and it does not
have any memory
It takes current input but here we require previous state
which they do not consider it
To overcome this problem, we need RNN which have
memory and previous data and current input
It also use loop method means when output comes again it goes
input state
It also consider previous state but suppose it has not previous
state then it use0s at starting Initial Hidden State
Which is H0 and previous hidden state and X1 current input
both process it uses with first Time Step then output will be
Current Hidden State
• Unsupervised Learning
• Reinforcement Learning f
Supervised Learning
Our main is that how to make intelligent the machine in supervise learning e
have training data means supervise means supervisor (teacher) and we have
input data and output data which we create a model and that model we put
new input and check valid output Example : Exit poll in Election
Now here learning algorithm works like Naïve Bayes input your
algorithm is learning and classifying means it will check the
probability of wining or loosing so this is supervised
learning
As the name suggests, this type of learning is done under the
supervision of a teacher. This learning process is dependent.
During the training of ANN under supervised learning, the input
vector is presented to the network, which will give an output
vector. This output vector is compared with the desired output
vector. An error signal is generated, if there is a difference
between the actual output and the desired output vector.
On the basis of this error signal, the weights are adjusted
until the actual output is matched with the desired output.
Used Learning Algorithm Naïve Bayes Algorithm
Which apply input and output given and again given New
Input actual counting in exit poll and prepare in Model
And find out result probability or output
Naïve Bayes theorem usage in Supervised Learning
Where we need to predict for any result for example Email is
spam or Not spam here we need to classify which requires
Bays theorem
What is the probability if the Red ball is taken out from Bag1
-> (B1/R) so this is called cause property means Reverse
method
Red ball is taken from Bag1 means Ball is Given Red from
Bag1 -> 1/2 X 2/5-> B1/R
So formula is Bays Theorem P(Y/X) = P(X/Y) * P(Y) / P(X)
Here X is given that Red Ball and find out of Red is taken
from Bag1
= R/B1 * B1
P(X) P(R)
= 2/5 * 1/2
= 1/5
1/5+2/7
P(Y/X1,X2…….Xn) = P(X1/Y)*P(X2/Y)*P(X3/Y)……P(Xn/Y)*P(Y)
P(X1) *P(X2)*P(X3)……P(Xn)
P(N/X)= P(X/N)*P(N)
P(X)
P(N/X1,X2…….Xn) = P(X1/N)*P(X2/N)*P(X3/N)……P(Xn/N)*P(N)
P(X1) *P(X2)*P(X3)……P(Xn)
Suppose Fever was Yes and We have Two Factor X1, X2
X1=Covid , X2=Flu
P(X1/Y)*P(X2/Y)
P(Y/X1,X2)= P(X1/Y)*P(X2/Y) * P(Y) / P(X1) *P(X2)……..n
=4/7*3/7* 7/10
=12/70
Unsupervised Learning
1. Regression Algorithm
Linear Regression
Y=mX+b
m is the slope of the line (how much Y changes for a unit change
in X)
=12/8=1.5
= 13 – 15 = -2
Y=mX+b
=1.5*20+(-2)
=30-2=28$
• Decision Trees
• Random Forest
• Logistic Regression
Random Forest
• Binary Classifier
• Multiclass Classifier :
we don’t give label data I/O Here pattern are checked with
cluster suppose we give different shape in input like triangle
which needs to recognize the pattern in unsupervised from
other shapes now when we give new
shape than it does not match with other shape then this
rectangle shape puts into that group
In the real world, we do not always input data with the
corresponding output so to solve such cases we need
unsupervised learning
in this learning use K-mean clustering
Example :
Market Basket Analysis :
Reinforcement Learning
Reinforcement Learning is a feedback-based machine learning
Technique in which an agent learns to behave in an environment
by performing an action and seeing the result. For a good action,
the agent gets positive feedback, and for a bad action, the agent
gets negative feedback or a penalty.
There is no labeled data. So the agent is bound to learn by
its experience
Reinforcement Learning solves a specific type of problem where
decision-making is sequential and the goal is long-term, such as
game-play robotics.
Advantages of supervised
With the help of supervised learning the model can predict on the
basis of prior experiance
In Supervised Learning, we can Have an exact idea about the
class of the object
Supervised Learning model helps us to solve various real world
problem such as fraud detection, spam filtering
Disadvantages
Supervised Learning models are not suitable for complex task
If the test data is different from the training data then it can not
predict the correct output
Training required lots of computation times
We need enough knowledge about class of objects means images
of Fruits and their label
Perceptron Rule
X Y
Y = X1W1+X2W2…..XnWn +b
Step function : Y > 0 -> 1
Y < 0 -> -1
So this is also activation function
error e(t) = Y (desired o/p) – Y (Actual o/p)
Set the initial value is w1, w2………. Wn
In Supervised Learning, we have input and also output which
is labeled data or training data
On the basis of training data, we create a Model and again
give new input and check the output
q
Y=mX+b
Need of bias
Now, Suppose if b was absent, then the graph will be formed like this:
Due to absence of bias, model will train over point passing through origin
only, which is not in accordance with real-world scenario
w1=0.5
w2=-0.3
b1=0.1
Why we use Activation functions with Neural Networks?
Yes a perceptron (one fully connected unit) can be used for regression.
It will just be a linear regression. If you use no activation function you
get a regression and if you put a sigmoid activation you get a
classifier
f(z) = w1.x1+w2.x2+w3.x3 + b
ax+by+cz+b > 0
Linear Regression
Y=mX+b
• Linear summation of inputs: In the above diagram, it has
two inputs x1, x2 with weights w1, w2, and bias b. And the
linear sum z = w1 x1 + w2 x2 + … + wn xn + b
Perceptron Rule
in Perceptron we use Loop
Our goal is to find the line in the Graph means We have to find
out ABC Value to classify the data
• We start A=1, B=1, C=0 from Random Value
• Run Loop and
• 3
• Select a point or student
• Check the point in the positive region or classified data
• Again check if it is a misclassification
• Change the ABC value and to make classification data
• Again repeat step no. 3,4 and 5 then go to step no. 6
Loop can be run in 1000 times or the second option till while
convergence check how many points are misclassified until it
becomes zero the loop will be executed after that it be
terminated
And the convergence done successfully loop will be terminated
Here we have convergence and another option epoc means no. of
Dvsdvs
-3x+y+4=0
For training, this network is using the Hebb or Delta learning rule.
Step 1 − Initialize all the weights to zero as wij = 0, i=1 to n, j=1 to n
Step 2 − Perform steps 3-4 for each input vector.
Step 3 − Activate each input unit as follows −
xi=si(i=1ton)xi=si(i=1ton)
Step 4 − Activate each output unit as follows −
yj=sj(j=1ton)yj=sj(j=1ton)
wij(new)=wij(old)+xiyjwij(new)=wij(old)+xiyj
Hebb rule :
Calculate the New Weight value
Activate each input unit as follows −
xi=si(i=1 to n) xi=si(i=1 to n)
Step 4 − Activate each output unit as follows −
yj=sj(j=1 to n) yj=sj(j=1 to n)
Step 5 − Adjust the weights as follows −
wij(new)=wij(old)+xiyj
Outer Product Rule
Wn = [S]t * [T]
t=transpose matrices, T=Target Matrics
Check the auto-associative network for input vector [1 1 -1] from
the weight vector with no self connection. Test whether the net is
able to recognize with one missing entry.
Input vector x = [1 1 -1]
And here no self connection in Weight -> No W i Which is 0
Here St= target input and transpose of input
W = ∑ST x t = |1|
|1| [1 1 -1]
|-1|
[1 1 -1] [0 1 -1]
[1 1 -1] = [1 0 -1]
[-1 -1 1] [-1 -1 0]
[0 1 -1]
Y = x.W = [1 0 -1] [1 0 -1]
[-1 -1 0]
[1 2 -1]
Gradient Descent
Gradient Descent is an optimization algorithm which means to find out
best result for the algorithm and it is a optimization technique if we
give differentiable function then gradient function will give the minimal
result
here i have taken data set suppose here cgpa lpa of four student
cgpa lpa
Real world data affects the real world factor suppose student not
place in desired lpa may be he was not suited or qualified
interviewed which is called stochastic error
and due to stochastic error data becomes sort of linear
Backpropagation
It is a algorithm to train neural network
This is a supervised learning algorithm used for training a
deep-learning model
This learning method is the most popular at the moment
because it makes possible the use of powerful calculation
with low computation time
Backpropagation Algo => Train NN
In backpropagation we check errors after the calculation
of the Linear Activation Function
Y = X1W1+X2W2…..XnWn +b
Here X vector input data and Y Vector our data are not same.
L = (3-18)2
= 225
Now we have to reduce error because Neural Network is
3 LPA here actual data output y i.e, 3 and ŷ i.e, 18 which
prediction of Neural Network
ŷ Here is O21
O21 = W211 . O11 + W221 . O12 + b21
Now can these are complex hierarchy so If I have to minimize loss then
we can change the value of bias and weight value but we cannot
change cgpa and iq value because that is our data
So to minimize and decrease the loss then we go to previous or back
step to change the value of weight and bias which is called
backpropagation
Backpropagation Error= Actual Output – Desired Output
Because we are approaching to solve this error after go to back step to
update the value of Weight and Bias using with Gradient descent
Step 4 : Here update the weight and bias value using with gradient
descent
W new = W old – Learning rate times partial derivative of loss
function with respect to weight
Similarly, it is applicable in b value
Gradient descent
Gradient descent is an optimization algorithm that's used when training
a machine learning model.
Best fit line means which can minimize the error on y direction
The sum square of Difference of Actual y value and predicted y value
should be minimum
M is the slop in the line
Here we make a simple discussion and assumes m=78.35
n
L= ∑ (yi - ŷ)2
i
Step 1 :In Gradient Descent select random value of b let assume b= -10
set the b value to reach minimum value at L
How do we know to check L minimum after decreasing or increasing of
b so we can find it from slope
How to find out a particular slope of a function let assume we have
function
y=x2 + 2 and x=5 given and what is slope then we differentiate dy/dx=
2x
so dy/dx = 10 this function belongs to 10 on the slop
suppose when we find slop and if the slope is negative then we move
forward means increase the b value and if the slope is positive then
go backward and decrease the b value so if you want b new value
b new = b old – slope
this is gradient descent
initially we had b=-10 and suppose slope = - 50
then b new = -10 –(-50)
b new = 40 which you move forward
L
b
again we take b value suppose b=b10 and slop = 50
b new = b old – slope
= 10 – 50 = -40
L
b
L L
30 40 b b
move backward
Linear Regression
Slope -> m= tanθ
Simple Linear Regression
This is the simplest form of linear regression, and it involves only one
independent variable and one dependent variable. The equation for
simple linear regression is:
y=mX+β
where:
Y is the dependent variable
X is the independent variable
β is the intercept
m is the slope
Suppose a student could not qualify enough lpa after having maximum
cgpa what is reason then why does it happen because real world data
affects from real factors which u can not understand by
mathematically what was reason for this lpa which you can not
qyantify so this called stochastic error
And due to stochastic error, which we can not determine and data
becomes sort of linear
3. Suppose if we have sort of linear data then we put perfect line
and touch to the point which is best fit line
(m, b)
OLS Gradient
Descent
Linear
SGD
Regression
Figure 1 Regressor
class
2
where di is distance and y^ is the prediction 4
output and yi is the actual output so the this d
shows the difference with error for a particular
student and total error is which add all errors.
Total Error is for all student
3
Multiple Linear Regression
Here multiple input are required for this problem.
let x1,x2,x3 are input and independent data and y is output dependent
so multiple linear regression is just extension of simple linear
regression and in reverse order simple linear regression is just
specialization of multiple linear regression
let takes example for 100 students and we have cgpa, iq, gender, lpa
Cgpa Iq Gender Lpa
x1 X2 X3 Y
1
2
.
.
100
The goal of the algorithm is to find the best Fit Line equation that can
predict the values based on the independent variables.
X1 : cgpa X2 : iq Y
here data is 3 D
LPA
** ***
******
** * * * * *
cgpa
IQ
in 2 D y= mx+b
here in 3D formula y= mx1+nx2+b
y=β0+β1X1+β2X2 β0, β1, β2
here in 4D formula
y=β0+β1X1+β2X2+β3X2 β0, β1, β2, β3
if Data Set n dimensional
y=β0+β1X1+β2X2+β3X2……….+βnX2
n
y = β0+ ∑ βiXi
i=1
if n=1
y=β0 + β1x1
so linear regression we try to find out coefficient value if we have 1
input column then we find out 2 coefficient value
and if we have 2 input column then we find out 3 coefficient value
if we have n input columns then we find out n+1 coefficient value
earlier we have 3D data set
cgpa –x1, iq -> x2, y ->lpa and suppose if you have value of β0, β1, β2
y=β0+β1X1+β2X2 here if you want to calculate lpa
lpa = β0 + β1* cgpa + β2*iq
so if we can find out lpa for a new student then above formula we can
evaluate it.
here coefficient represents like weight in the above formula β2
mentioned what is the weightage of IQ to calculate the LPA
if β1 > β2 then we can imagine cgpa plays an important role as
compared to iq if lpa is calculated
β0 is offset means intercept value and if cgpa =0 and iq = 0 then it is
decided by intercept values to calculate the LPA
calculate 100 student predicted lpa ŷ
1 student Cgpa x1 IQ x2 Gender x3