AI Unit 4
AI Unit 4
Machine Learning
Machine Learning is the field of study that gives computers the capability to learn without being explicitly
programmed. ML is one of the most exciting technologies that one would have ever come across. As it is
evident from the name, it gives the computer that makes it more similar to humans: The ability to learn.
Machine learning is actively being used today, perhaps in many more places than one would expect.
Machine learning is the sub field of AI in which we try to improve decision making power of
intelligent agents. Agent has a performance element that decides what actions to take and a learning
element that modifies the performance element so that it makes better decisions. Design of learning
element is affected by following three major factors:
1) Which components of performance element are to be learned.
2) What feedback is available to learn these components.
3) What is representation method used for components.
Following are some ways of learning mostly used in machines:
(A) Logical learning (B) Inductive learning (C) Deductive
learning.
Logical Learning: In this process a new concept or solution through the use of similar known
concepts. We use this type of learning when solving problems on an exam , where previously learned
examples serve as a guide or when we learn to drive a truck using our knowledge of car driving.
Inductive Learning: This technique requires the use of inductive inference, a form of invalid but
useful inference. We use inductive learning when we formulate a general concept after seeing a
number of instances or examples of the concept. E.g : When we learn the concept of color or sweet
taste after experiencing sensation associated with several objects.
Deductive Learning: This is performed through a sequence of deductive inference steps using known
facts. From the known facts , new facts or relationships are logically delivered. E.g : If we have an
information that weather is Hot and Humid then we can infer that it may Rain also. Another example
may be , let
P → Q & Q → R , 𝑡ℎ𝑒𝑛 𝑤𝑒 𝑐𝑎𝑛 𝑖𝑛𝑓𝑒𝑟 𝑡ℎ𝑎𝑡 𝑃 → 𝑅
Image Recognition
Speech Recognition
Recommender Systems
Fraud Detection
Self- Driving Cars
Medical Diagnosis
Stock Market Trading
Virtual Try On
Key Differences Between Artificial Intelligence (AI) and Machine Learning (ML)
These ML algorithms help to solve different business problems like Regression, Classification,
Forecasting, Clustering, and Associations, etc.
Based on the methods and way of learning, machine learning is divided into mainly four types, which are:
Let's understand supervised learning with an 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 the 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's 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.
Categories of Supervised Machine Learning
Supervised machine learning can be classified into two types of problems, which are given below:
Classification
Regression
a) Classification
Classification algorithms are used to solve the classification problems in which the output variable is
categorical, such as "Yes" or No, Male or Female, Red or Blue, etc. The classification algorithms
predict the categories present in the dataset. Some real-world examples of classification algorithms are
Spam Detection, Email filtering, etc.
b) Regression
Regression algorithms are used to solve regression problems in which there is a linear relationship
between input and output variables. These are used to predict continuous output variables, such as market
trends, weather prediction, etc.
Advantages:
Since supervised learning work with the labelled dataset so we can have an exact idea about the classes of
objects.
These algorithms are helpful in predicting the output on the basis of prior experience.
Disadvantages:
Image Segmentation:
Supervised Learning algorithms are used in image segmentation. In this process, image classification is
performed on different image data with pre-defined labels.
Medical Diagnosis:
Supervised algorithms are also used in the medical field for diagnosis purposes. It is done by using medical
images and past labelled data with labels for disease conditions. With such a process, the machine can
identify a disease for the new patients.
Fraud Detection –
Supervised Learning classification algorithms are used for identifying fraud transactions, fraud customers,
etc. It is done by using historic data to identify the patterns that can lead to possible fraud.
Spam detection –
In spam detection & filtering, classification algorithms are used. These algorithms classify an email as spam
or not spam. The spam emails are sent to the spam folder.
Speech Recognition –
Supervised learning algorithms are also used in speech recognition. The algorithm is trained with voice
data, and various identifications can be done using the same, such as voice-activated passwords, voice
commands, etc.
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.
The main aim of the unsupervised learning algorithm is to group or categories the unsorted dataset
according to the similarities, patterns, and differences. Machines are instructed to find the hidden
patterns from the input dataset.
Let's take an example to understand it more preciously; 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:
Clustering
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.
Some of the popular clustering algorithms are given below:
2) Association
Association rule learning is an unsupervised learning technique, which finds interesting relations among
variables within a large dataset. The main aim of this learning algorithm is to find the dependency of one
data item on another data item and map those variables accordingly so that it can generate maximum
profit. This algorithm is mainly applied in Market Based analysis, Web usage mining, continuous
production, etc.
Some popular algorithms of Association rule learning are Apriori Algorithm, Eclat, FP-growth
algorithm.
Advantages:
These algorithms can be used for complicated tasks compared to the supervised ones because these
algorithms work on the unlabeled dataset.
Unsupervised algorithms are preferable for various tasks as getting the unlabeled dataset is easier as
compared to the labelled dataset.
Disadvantages:
The output of an unsupervised algorithm can be less accurate as the dataset is not labelled, and algorithms
are not trained with the exact output in prior.
Working with Unsupervised learning is more difficult as it works with the unlabelled dataset that does not
map with the output.
Network Analysis: Unsupervised learning is used for identifying plagiarism and copyright in document
network analysis of text data for scholarly articles.
Recommendation Systems: Recommendation systems widely use unsupervised learning techniques for
building recommendation applications for different web applications and e-commerce websites.
Anomaly Detection: Anomaly detection is a popular application of unsupervised learning, which can
identify unusual data points within the dataset. It is used to discover fraudulent transactions.
Singular Value Decomposition: Singular Value Decomposition or SVD is used to extract particular
information from the database. For example, extracting information of each user located at a particular
location.
3. Semi-Supervised Learning
Semi-Supervised learning is a type of Machine Learning algorithm that lies between Supervised and
Unsupervised machine learning. It represents the intermediate ground between Supervised (With
Labelled training data) and Unsupervised learning (with no labelled training data) algorithms and uses the
combination of labelled and unlabeled datasets during the training period.
Although Semi-supervised learning is the middle ground between supervised and unsupervised learning
and operates on the data that consists of a few labels, it mostly consists of unlabeled data. As labels are
costly, but for corporate purposes, they may have few labels. It is completely different from supervised
and unsupervised learning as they are based on the presence & absence of labels.
To overcome the drawbacks of supervised learning and unsupervised learning algorithms, the
concept of Semi-supervised learning is introduced. The main aim of semi-supervised learning is to
effectively use all the available data, rather than only labelled data like in supervised learning. Initially,
similar data is clustered along with an unsupervised learning algorithm, and further, it helps to label the
unlabeled data into labelled data. It is because labelled data is a comparatively more expensive acquisition
than unlabeled data.
We can imagine these algorithms with an example. Supervised learning is where a student is under the
supervision of an instructor at home and college. Further, if that student is self-analysing the same concept
without any help from the instructor, it comes under unsupervised learning. Under semi-supervised
learning, the student has to revise himself after analyzing the same concept under the guidance of an
instructor at college.
Advantages:
Disadvantages:
4. Reinforcement Learning
Reinforcement learning works on a feedback-based process, in which an AI agent (A software
component) automatically explore its surrounding by hitting & trail, taking action, learning from
experiences, and improving its performance. Agent gets rewarded for each good action and get
punished for each bad action; hence the goal of reinforcement learning agent is to maximize the rewards.
In reinforcement learning, there is no labelled data like supervised learning, and agents learn from their
experiences only.
The reinforcement learning process is similar to a human being; for example, a child learns various things
by experiences in his day-to-day life. An example of reinforcement learning is to play a game, where the
Game is the environment, moves of an agent at each step define states, and the goal of the agent is to get a
high score. Agent receives feedback in terms of punishment and rewards.
Due to its way of working, reinforcement learning is employed in different fields such as Game theory,
Operation Research, Information theory, multi-agent systems.
A reinforcement learning problem can be formalized using Markov Decision Process(MDP). In MDP,
the agent constantly interacts with the environment and performs actions; at each action, the environment
responds and generates a new state.
Video Games:
RL algorithms are much popular in gaming applications. It is used to gain super-human performance. Some
popular games that use RL algorithms are AlphaGO and AlphaGO Zero.
Resource Management:
The "Resource Management with Deep Reinforcement Learning" paper showed that how to use RL in
computer to automatically learn and schedule resources to wait for different jobs in order to minimize
average job slowdown.
Robotics:
RL is widely being used in Robotics applications. Robots are used in the industrial and manufacturing area,
and these robots are made more powerful with reinforcement learning. There are different industries that
have their vision of building intelligent robots using AI and Machine learning technology.
Text Mining
Text-mining, one of the great applications of NLP, is now being implemented with the help of
Reinforcement Learning by Salesforce company.
Advantages
It helps in solving complex real-world problems which are difficult to be solved by general techniques.
The learning model of RL is similar to the learning of human beings; hence most accurate results can be
found.
Helps in achieving long term results.
Disadvantage
The curse of dimensionality limits reinforcement learning for real physical systems.
Example: Suppose there is a candidate who has a job offer and wants
to decide whether he should accept the offer or Not. So, to solve this
problem, the decision tree starts with the root node (Salary attribute by
ASM). The root node splits further into the next decision node
(distance from the office) and one leaf node based on the
corresponding labels. The next decision node further gets split into one
decision node (Cab facility) and one leaf node. Finally, the decision
node splits into two leaf nodes (Accepted offers and Declined offer).
Consider the below diagram:
1. Information Gain:
Information gain is the measurement of changes in entropy after the
segmentation of a dataset based on an attribute.
It calculates how much information a feature provides us about a class.
According to the value of information gain, we split the node and build
the decision tree.
A decision tree algorithm always tries to maximize the value of
information gain, and a node/attribute having the highest information gain
is split first. It can be calculated using the below formula:
Where,
S= Total number of samples
P(yes)= probability of yes
P(no)= probability of no
2. Gini Index:
Gini index is a measure of impurity or purity used while creating a
decision tree in the CART(Classification and Regression Tree) algorithm.
An attribute with the low Gini index should be preferred as compared to
the high Gini index.
It only creates binary splits, and the CART algorithm uses the Gini index
to create binary splits.
Gini index can be calculated using the below formula:
Gini Index= 1- ∑jPj2
Probability
Probability theory is of utmost importance in machine learning as it provides the foundation for modeling
uncertainty and making probabilistic predictions. How could we quantify the likelihood of different
outcomes, events, or simply numerical values? Probability helps with that! In addition, Probability
distributions are especially important in machine learning and make all the magic happen.
Descriptive Statistics
Descriptive statistics enable us to understand the characteristics and properties of datasets. They help us
summarize and visualize data, identify patterns, detect outliers, and gain initial insights that inform
subsequent modeling and analysis.
The mean, median, and mode provide valuable insights into the central or representative values of a
dataset. In machine learning, they aid in data preprocessing by assisting with the imputation of missing
values and identifying potential outliers.
Variance and Standard Deviation
Variance and standard deviation quantify the spread or dispersion of data points around the central
tendency. They serve as indicators of data consistency and variability in machine learning.
These measures are useful for feature selection or dimensionality reduction, identifying features with
Measure of Spread
Range, interquartile range, and percentiles are measures of spread that offer insights into the distribution of
data values. They are particularly valuable in outlier detection, as they help identify and address outliers
that can greatly influence model training and predictions
Sampling
Machine learning models are trained based on sampled data. If the samples are not carefully selected, the
reliability of our models becomes uncertain. Ideally, we aim to choose representative subsets of data from
larger populations.
Estimation
Estimation techniques are crucial in machine learning for determining unknown population parameters
based on sample data. They allow us to estimate model parameters, evaluate model performance, and
make predictions about unseen data.
The most common estimation method used in machine learning is Maximum Likelihood (ML) estimation,
which finds the estimator of an unknown parameter by maximizing the likelihood function.
Linear regression is a term commonly encountered in the statistical literature, but it is more than just that.
It is also seen as a supervised learning algorithm that captures the connection between a dependent
variable and independent variables.
Logistic Regression
Logistic regression is a statistical classification algorithm that estimates the probability of categorical
outcomes based on independent variables. By applying a logistic function, it predicts the occurrence of a
particular class.
Decision Trees
Decision trees are versatile algorithms that use statistics to split data based on features, creating a tree-like
structure for classification or regression. They are intuitive, interpretable, and handle categorical and
numerical data.
Random Forest
Random Forest is an ensemble learning method that improves prediction accuracy by combining multiple
decision trees. It employs sampling to randomly select subsets of features and data for building the trees.
The predictions of these individual trees are then aggregated to make the final prediction.
Support Vector Machines (SVM)
SVM is a powerful algorithm that can be used for classification and regression tasks. It uses statistical
principles to create a boundary between different groups of data points, making it easier to tell them apart.
By optimizing this boundary, SVM reduces the chances of making mistakes and improves overall
KNN is a simple yet effective algorithm used for classifying data points based on the majority vote of their
nearest neighbors. It is suitable for both classification and regression problems and does not require
training.
Where,
Problem: If the weather is sunny, then the Player should play or not?
0 Rainy Yes
1 Sunny Yes
2 Overcast Yes
3 Overcast Yes
4 Sunny No
5 Rainy Yes
6 Sunny Yes
7 Overcast Yes
8 Rainy No
9 Sunny No
10 Sunny Yes
11 Rainy No
12 Overcast Yes
13 Overcast Yes
Weather Yes No
Overcast 5 0
Rainy 2 2
Sunny 3 2
Total 10 4
Weather No Yes
Rainy 2 2 4/14=0.29
Sunny 2 3 5/14=0.35
Applying Bayes'theorem:
P(Yes|Sunny)= P(Sunny|Yes)*P(Yes)/P(Sunny)
P(Sunny)= 0.35
P(Yes)=0.71
P(Sunny|NO)= 2/4=0.5
P(No)= 0.29
P(Sunny)= 0.35
Naïve Bayes is one of the fast and easy ML algorithms to predict a class of datasets.
It can be used for Binary as well as Multi-class Classifications.
It performs well in Multi-class predictions as compared to the other Algorithms.
It is the most popular choice for text classification problems.
Naive Bayes assumes that all features are independent or unrelated, so it cannot learn the relationship
between features.
1. Missing Data:
o Sometimes, certain variables in a dataset may have missing values. Learning with hidden
data involves developing methods to handle and impute these missing values to make the
most accurate predictions.
2. Latent Variables:
o In many models, there are latent variables that are not directly observable but influence the
observed data. For example, in clustering problems, the latent variable might represent the
cluster assignment of each data point.
3. Unobservable Factors:
o Hidden data can also represent factors that are not directly measurable but have a
significant impact on the observed data. These factors may include underlying trends,
patterns, or characteristics that are not apparent in the given data.
1. Initialization:
o Initialize the model parameters randomly or based on some prior knowledge.
2. Expectation (E-step):
o Estimate the expected values of the latent variables given the observed data and the current
parameter estimates. Compute the posterior distribution of the hidden variables.
3. Maximization (M-step):
o Update the model parameters by maximizing the expected log-likelihood obtained from the E-step.
This involves finding parameter values that increase the likelihood of the observed data given the
estimated latent variable distribution.
4. Iteration:
o Repeat the E-step and M-step iteratively until the algorithm converges. At each iteration, the model
parameters are refined, leading to improved estimates of both observable and hidden data.