AI using Python
AI using Python
Example: Suppose we have an input dataset of Cats and Dog images. So, first,
we will provide the training to the machine to understand the images, such as
shape & size of the tail of cat and dog, Shape of eyes, colour, height (dogs are
taller, cats are smaller), etc. After completion of training, we input the picture
of a cat and ask the machine to identify the object and predict the output. Now,
the machine is well trained, so it will check all the features of the object, such as
height, shape, colour, eyes, ears, tail, etc., and find that it is a cat. So, it will put
it in the Cat category. This is the process of how the machine identifies the objects
in Supervised Learning.
The main goal of the supervised learning technique is to map the input variable(x)
with the output variable(y). Some real-world applications of supervised learning
are Risk Assessment, Fraud Detection, Spam filtering, etc.
Supervised machine learning can be classified into two types of problems, which
are given below:
o Classification
o Regression
a) Classification
b) Regression
In unsupervised learning, the models are trained with the data that is neither
classified nor labelled, and the model acts on that data without any supervision.
Example: Suppose there is a basket of fruit images, and we input it into the
machine learning model. The images are totally unknown to the model, and the
task of the machine is to find the patterns and categories of the objects.
So, now the machine will discover its patterns and differences, such as colour
difference, shape difference, and predict the output when it is tested with the test
dataset.
Unsupervised Learning can be further classified into two types, which are given
below:
o Clustering
o Association
1) Clustering
The clustering technique is used when we want to find the inherent groups from
the data. It is a way to group the objects into a cluster such that the objects with
the most similarities remain in one group and have fewer or no similarities with
the objects of other groups. An example of the clustering algorithm is grouping
the customers by their purchasing behaviour.
2) Association
4. Reinforcement Learning
The Naive Bayes algorithm is comprised of two words Naive and Bayes, which
can be described as:
o Bayes' theorem is also known as Bayes' Rule or Bayes' law, which is used
to determine the probability of a hypothesis with prior knowledge. It
depends on the conditional probability.
o The formula for Bayes' theorem is given as:
Where,
Working of Naïve Bayes' Classifier can be understood with the help of the below
example:
o Naïve Bayes is one of the fast and easy ML algorithms to predict a class of
datasets.
o It can be used for Binary as well as Multi-class Classifications.
o It performs well in multi-class predictions as compared to the other
Algorithms.
o It is the most popular choice for text classification problems.
There are three types of Naive Bayes Model, which are given below:
Feedback ANN:
In this type of ANN, the output returns into the network to accomplish the best-
evolved results internally. As per the University of Massachusetts, Lowell
Centre for Atmospheric Research. The feedback networks feed information back
into itself and are well suited to solve optimization issues. The Internal system
error corrections utilize feedback ANNs.
Feed-Forward ANN:
Convolutional Neural Network consists of multiple layers like the input layer,
Convolutional layer, Pooling layer, and fully connected layers.
The Convolutional layer applies filters to the input image to extract features,
the Pooling layer down-samples the image to reduce computation, and the
fully connected layer makes the final prediction. The network learns the
optimal filters through backpropagation and gradient descent.
Convolutional Layers: Apply filters to the input data to produce feature
maps.
Pooling Layers: Reduce the dimensionality of the feature maps.
Dense Layer: A Dense Layer (also known as a Fully Connected Layer)
Perform the final classification or regression task. In this, every neuron is
connected to every neuron in the previous layer, making it "fully
connected."
Output Layer: It is the final layer that produces the result of the network’s
computations. It provides the final predictions or classifications for a given
input.
Types of CNN:-
1. LeNEt
2. VGGNet
3. AlexNet
4. GoogLeNet
The face recognition is a technique to identify or verify the face from the digital
images or video frame. A human can quickly identify the faces without much
effort. It is an effortless task for us, but it is a difficult task for a computer. There
are various complexities, such as low resolution, occlusion, illumination
variations, etc. These factors highly affect the accuracy of the computer to
recognize the face more effectively. First, it is necessary to understand the
difference between face detection and face recognition.
Face Detection: The face detection is generally considered as finding the faces
(location and size) in an image and probably extract them to be used by the face
detection algorithm.
Face Recognition: The face recognition algorithm is used in finding features that
are uniquely described in the image. The facial image is already extracted,
cropped, resized, and usually converted in the grayscale.
Basic Concept of HAAR Cascade Algorithm
OpenCV provides the trainer as well as the detector. We can train the classifier
for any object like cars, planes, and buildings by using the OpenCV. There are
two primary states of the cascade image classifier first one is training and the
other is detection.
For training, we need a set of samples. There are two types of samples:
Face recognition is a simple task for humans. Successful face recognition tends
to effective recognition of the inner features (eyes, nose, mouth) or outer features
(head, face, hairline).
The basic idea of face recognition is based on the geometric features of a face. It
is the feasible and most intuitive approach for face recognition. The first
automated face recognition system was described in the position of eyes, ears,
nose. These positioning points are called features vector (distance between the
points).
It compares the input facial image with the facial image related to the user, which
is required authentication. It is a 1x1 comparison.
It basically compares the input facial images from a dataset to find the user that
matches that input face. It is a 1xN comparison.
o Eigenfaces (1991)
o Local Binary Patterns Histograms (LBPH) (1996)
o Fisherfaces (1997)
o Scale Invariant Feature Transform (SIFT) (1999)
o Speed Up Robust Features (SURF) (2006)
Q5. What is NLP? Describe its components in detail. Also
describe its steps.
Components of NLP:-
Applications of NLP:-
1. Lexical Analysis and Morphological: The first phase of NLP is the Lexical Analysis.
This phase scans the source code as a stream of characters and converts it into
meaningful lexemes. It divides the whole text into paragraphs, sentences, and words.
Example: Agra goes to the Poonam. In the real world, Agra goes to the Poonam, does
not make any sense, so this sentence is rejected by the Syntactic analyzer.
Advantages of NLP:-
o NLP helps users to ask questions about any subject and get a direct
response within seconds.
o NLP offers exact answers to the question means it does not offer
unnecessary and unwanted information.
o NLP helps computers to communicate with humans in their languages.
o It is very time efficient.
o Most of the companies use NLP to improve the efficiency of
documentation processes, accuracy of documentation, and identify the
information from large databases.
Disadvantages of NLP:-
A list of disadvantages of NLP is given below:
Steps:
2. Boosting:-
Steps:
Example Algorithms:
Description: Stacking involves training multiple models (base learners) and then
using another model (meta-learner) to combine their predictions.
Steps:
Types:
o Hard Voting: The class label that gets the most votes is the final prediction.
o Soft Voting: The probabilities of each class are averaged, and the class with
the highest average probability is chosen.
Example: Combining predictions from a logistic regression model, a
decision tree, and a k-nearest neighbours model using hard or soft voting.