MACHINE LEARNING
Machine learning (ML) is a branch of artificial intelligence (AI) that focuses on building systems
that can learn from and make decisions based on data. Instead of being explicitly programmed
with a set of rules, a machine learning model is trained on data to recognize patterns and make
predictions or decisions without human intervention.
Here's a basic breakdown of how it works:
1. Data: Machine learning starts with data—this could be anything from images, text,
numbers, or even audio. The more relevant and high-quality the data, the better the
machine will perform.
2. Model: The model is the mathematical framework that processes the data. You can think
of it like a recipe that the machine follows to make predictions. There are many types of
models, such as linear regression, decision trees, neural networks, etc.
3. Training: In this step, the model is "trained" on the data. During training, the model
learns patterns in the data, adjusting itself to minimize errors in its predictions. For
example, if the model is trying to predict house prices based on features like square
footage, location, etc., it will learn how each feature impacts the price.
4. Testing: After training, the model is tested on new, unseen data to check how well it
performs. This helps determine if the model is good at generalizing to new situations, or
if it just memorized the training data.
5. Prediction: Once the model is trained and tested, it can be used to make predictions on
new data.
Types of Machine Learning
1. Supervised Learning: The model is trained on labeled data (data with known outcomes),
and it learns to predict the output based on that input.
o Example: Predicting house prices based on features like location, size, and
number of rooms.
2. Unsupervised Learning: The model is trained on unlabeled data (data with no known
outcomes), and it tries to find hidden patterns in the data.
o Example: Grouping customers into different segments based on their purchasing
behavior.
3. Reinforcement Learning: The model learns by interacting with an environment, taking
actions, and receiving feedback (rewards or penalties) to maximize some long-term goal.
o Example: Training a robot to walk by rewarding it when it moves in the right
direction and penalizing it when it falls.
Common Applications
Image recognition (like recognizing faces in photos)
Speech recognition (like voice assistants, e.g., Siri or Alexa)
Recommendation systems (e.g., Netflix or Amazon recommendations)
Natural Language Processing (NLP) (like chatbots or language translation)
There are three main types of machine learning: Supervised Learning, Unsupervised
Learning, and Reinforcement Learning. Let’s break each one down:
1. Supervised Learning
Supervised learning is where the model is trained on labeled data. This means that the training
dataset contains input-output pairs, and the model learns to map inputs to the correct outputs.
How it works: The model is provided with both the input (features) and the correct
output (label), and it learns to make predictions or classifications based on the training
data.
Goal: Minimize the error between the predicted output and the actual output.
Example:
o Classification: Predicting whether an email is spam or not based on labeled data
(spam, not spam).
o Regression: Predicting house prices based on features like square footage,
location, etc. (the output is a continuous value).
Common algorithms:
o Linear Regression
o Logistic Regression
o Decision Trees
o k-Nearest Neighbors (k-NN)
o Support Vector Machines (SVM)
o Neural Networks
2. Unsupervised Learning
Unsupervised learning is when the model is trained on data that doesn't have labels (i.e., no
predefined output). The goal is to find hidden patterns or structures within the data.
How it works: The model is given data without any labeled output and tries to find
structure or relationships within the data, like grouping similar data points together or
reducing the dimensionality of the data.
Goal: Discover hidden patterns, structures, or associations in the data.
Example:
o Clustering: Grouping customers into different segments based on purchasing
behavior.
o Dimensionality reduction: Reducing the number of features in a dataset while
retaining important information (e.g., using PCA).
Common algorithms:
o k-Means Clustering
o Hierarchical Clustering
o Principal Component Analysis (PCA)
o t-Distributed Stochastic Neighbor Embedding (t-SNE)
3. Reinforcement Learning
Reinforcement learning is a type of machine learning where an agent learns to make decisions by
interacting with an environment. The agent receives rewards or penalties based on its actions,
and the goal is to maximize the cumulative reward over time.
How it works: The agent takes actions in the environment and gets feedback (rewards or
penalties). It learns to optimize its behavior to maximize the total reward.
Goal: Learn the optimal strategy (policy) that maximizes long-term rewards.
Example:
o Gaming: Training an AI to play a game like chess or Go, where the AI learns
optimal moves through trial and error.
o Robotics: Teaching a robot to walk by rewarding it when it takes a correct step
and penalizing it when it falls.
Common algorithms:
o Q-Learning
o Deep Q-Networks (DQN)
o Proximal Policy Optimization (PPO)
o Actor-Critic Methods
In supervised learning, models are trained using labelled dataset, where the model learns about
each type of data. Once the training process is completed, the model is tested on the basis of test
data (a subset of the training set), and then it predicts the output.
The working of Supervised learning can be easily understood by the below example and
diagram:
Suppose we have a dataset of different types of shapes which includes square, rectangle, triangle,
and Polygon. Now the first step is that we need to train the model for each shape.
o If the given shape has four sides, and all the sides are equal, then it will be labelled as
a Square.
o If the given shape has three sides, then it will be labelled as a triangle.
o If the given shape has six equal sides then it will be labelled as hexagon.
Now, after training, we test our model using the test set, and the task of the model is to identify
the shape.
The machine is already trained on all types of shapes, and when it finds a new shape, it classifies
the shape on the bases of a number of sides, and predicts the output.
Steps Involved in Supervised Learning:
o First Determine the type of training dataset
o Collect/Gather the labelled training data.
o Split the training dataset into training dataset, test dataset, and validation dataset.
o Determine the input features of the training dataset, which should have enough
knowledge so that the model can accurately predict the output.
o Determine the suitable algorithm for the model, such as support vector machine, decision
tree, etc.
o Execute the algorithm on the training dataset. Sometimes we need validation sets as the
control parameters, which are the subset of training datasets.
o Evaluate the accuracy of the model by providing the test set. If the model predicts the
correct output, which means our model is accurate.
Types of supervised Machine learning Algorithms:
Supervised learning can be further divided into two types of problems:
1. Regression
Regression algorithms are used if there is a relationship between the input variable and the
output variable. It is used for the prediction of continuous variables, such as Weather forecasting,
Market Trends, etc. Below are some popular Regression algorithms which come under
supervised learning:
o Linear Regression
o Regression Trees
o Non-Linear Regression
o Bayesian Linear Regression
o Polynomial Regression
2. Classification
Classification algorithms are used when the output variable is categorical, which means there are
two classes such as Yes-No, Male-Female, True-false, etc.
Spam Filtering,
o Random Forest
o Decision Trees
o Logistic Regression
o Support vector Machines
Note: We will discuss these algorithms in detail in later chapters.
Advantages of Supervised learning:
o With the help of supervised learning, the model can predict the output on the basis of
prior experiences.
o In supervised learning, we can have an exact idea about the classes of objects.
o Supervised learning model helps us to solve various real-world problems such as fraud
detection, spam filtering, etc.
Disadvantages of supervised learning:
o Supervised learning models are not suitable for handling the complex tasks.
o Supervised learning cannot predict the correct output if the test data is different from the
training dataset.
o Training required lots of computation times.
o In supervised learning, we need enough knowledge about the classes of object.
As the name suggests, unsupervised learning is a machine learning technique in which models
are not supervised using training dataset. Instead, models itself find the hidden patterns and
insights from the given data. It can be compared to learning which takes place in the human brain
while learning new things. It can be defined as:
Unsupervised learning is a type of machine learning in which models are trained using
unlabeled dataset and are allowed to act on that data without any supervision.
Unsupervised learning cannot be directly applied to a regression or classification problem
because unlike supervised learning, we have the input data but no corresponding output data. The
goal of unsupervised learning is to find the underlying structure of dataset, group that data
according to similarities, and represent that dataset in a compressed format.
Example: Suppose the unsupervised learning algorithm is given an input dataset containing
images of different types of cats and dogs. The algorithm is never trained upon the given dataset,
which means it does not have any idea about the features of the dataset. The task of the
unsupervised learning algorithm is to identify the image features on their own. Unsupervised
learning algorithm will perform this task by clustering the image dataset into the groups
according to similarities between images.
Why use Unsupervised Learning?
Below are some main reasons which describe the importance of Unsupervised Learning:
o Unsupervised learning is helpful for finding useful insights from the data.
o Unsupervised learning is much similar as a human learns to think by their own
experiences, which makes it closer to the real AI.
o Unsupervised learning works on unlabeled and uncategorized data which make
unsupervised learning more important.
o In real-world, we do not always have input data with the corresponding output so to solve
such cases, we need unsupervised learning.
Working of Unsupervised Learning
Working of unsupervised learning can be understood by the below diagram:
Here, we have taken an unlabeled input data, which means it is not categorized and
corresponding outputs are also not given. Now, this unlabeled input data is fed to the machine
learning model in order to train it. Firstly, it will interpret the raw data to find the hidden patterns
from the data and then will apply suitable algorithms such as k-means clustering, Decision tree,
etc.
Once it applies the suitable algorithm, the algorithm divides the data objects into groups
according to the similarities and difference between the objects.
Types of Unsupervised Learning Algorithm:
The unsupervised learning algorithm can be further categorized into two types of problems:
o Clustering: Clustering is a method of grouping the objects into clusters such that objects
with most similarities remains into a group and has less or no similarities with the objects
of another group. Cluster analysis finds the commonalities between the data objects and
categorizes them as per the presence and absence of those commonalities.
o Association: An association rule is an unsupervised learning method which is used for
finding the relationships between variables in the large database. It determines the set of
items that occurs together in the dataset. Association rule makes marketing strategy more
effective. Such as people who buy X item (suppose a bread) are also tend to purchase Y
(Butter/Jam) item. A typical example of Association rule is Market Basket Analysis.
Note: We will learn these algorithms in later chapters.
Unsupervised Learning algorithms:
Below is the list of some popular unsupervised learning algorithms:
o K-means clustering
o KNN (k-nearest neighbors)
o Hierarchal clustering
o Anomaly detection
o Neural Networks
o Principle Component Analysis
o Independent Component Analysis
o Apriori algorithm
o Singular value decomposition
Advantages of Unsupervised Learning
o Unsupervised learning is used for more complex tasks as compared to supervised
learning because, in unsupervised learning, we don't have labeled input data.
o Unsupervised learning is preferable as it is easy to get unlabeled data in comparison to
labeled data.
Disadvantages of Unsupervised Learning
o Unsupervised learning is intrinsically more difficult than supervised learning as it does
not have corresponding output.
o The result of the unsupervised learning algorithm might be less accurate as input data is
not labeled, and algorithms do not know the exact output in advance.
Reinforcement Learning (RL) is a branch of machine learning focused on making decisions to
maximize cumulative rewards in a given situation. Unlike supervised learning, which relies on a
training dataset with predefined answers, RL involves learning through experience. In RL, an
agent learns to achieve a goal in an uncertain, potentially complex environment by performing
actions and receiving feedback through rewards or penalties.
Key Concepts of Reinforcement Learning
Agent: The learner or decision-maker.
Environment: Everything the agent interacts with.
State: A specific situation in which the agent finds itself.
Action: All possible moves the agent can make.
Reward: Feedback from the environment based on the action taken.
How Reinforcement Learning Works
RL operates on the principle of learning optimal behavior through trial and error. The agent takes
actions within the environment, receives rewards or penalties, and adjusts its behavior to
maximize the cumulative reward. This learning process is characterized by the following
elements:
Policy: A strategy used by the agent to determine the next action based on the current
state.
Reward Function: A function that provides a scalar feedback signal based on the state
and action.
Value Function: A function that estimates the expected cumulative reward from a given
state.
Model of the Environment: A representation of the environment that helps in planning
by predicting future states and rewards.
Example: Navigating a Maze
The problem is as follows: We have an agent and a reward, with many hurdles in between. The
agent is supposed to find the best possible path to reach the reward. The following problem
explains the problem more easily.
The above image shows the robot, diamond, and fire. The goal of the robot is to get the reward
that is the diamond and avoid the hurdles that are fired. The robot learns by trying all the possible
paths and then choosing the path which gives him the reward with the least hurdles. Each right
step will give the robot a reward and each wrong step will subtract the reward of the robot. The
total reward will be calculated when it reaches the final reward that is the diamond.
Main points in Reinforcement learning –
Input: The input should be an initial state from which the model will start
Output: There are many possible outputs as there are a variety of solutions to a particular
problem
Training: The training is based upon the input, The model will return a state and the user
will decide to reward or punish the model based on its output.
The model keeps continues to learn.
The best solution is decided based on the maximum reward.
Difference between Reinforcement learning and Supervised learning:
Reinforcement learning Supervised learning
Reinforcement learning is all about
making decisions sequentially. In simple
words, we can say that the output In Supervised learning, the decision is made on
depends on the state of the current input the initial input or the input given at the start
and the next input depends on the output
of the previous input
In Reinforcement learning decision is In supervised learning the decisions are
dependent, So we give labels to independent of each other so labels are given to
sequences of dependent decisions each decision.
Example: Chess game,text
Example: Object recognition,spam detetction
summarization
Types of Reinforcement:
1. Positive: Positive Reinforcement is defined as when an event, occurs due to a particular
behavior, increases the strength and the frequency of the behavior. In other words, it has a
positive effect on behavior.
Advantages of reinforcement learning are:
Maximizes Performance
Sustain Change for a long period of time
Too much Reinforcement can lead to an overload of states which can diminish the
results
2. Negative: Negative Reinforcement is defined as strengthening of behavior because a
negative condition is stopped or avoided.
Advantages of reinforcement learning:
Increases Behavior
Provide defiance to a minimum standard of performance
It Only provides enough to meet up the minimum behavior
Elements of Reinforcement Learning
i) Policy: Defines the agent’s behavior at a given time.
ii) Reward Function: Defines the goal of the RL problem by providing feedback.
iii) Value Function: Estimates long-term rewards from a state.
iv) Model of the Environment: Helps in predicting future states and rewards for planning.
Supervised vs. Unsupervised Machine Learning
Supervised machine Unsupervised machine
Parameters learning learning
Algorithms are trained using Algorithms are used against
Input Data labeled data. data that is not labeled
Computational Complexity Simpler method Computationally complex
Accuracy Highly accurate Less accurate
No. of classes No. of classes is known No. of classes is not known
Data Analysis Uses offline analysis Uses real-time analysis of
Supervised machine Unsupervised machine
Parameters learning learning
data
Linear and Logistics
regression,KNN Random
K-Means clustering,
forest, multi-class
Hierarchical clustering,
classification, decision tree,
Apriori algorithm, etc.
Support Vector Machine,
Algorithms used Neural Network, etc.
Output Desired output is given. Desired output is not given.
Use training data to infer
No training data is used.
Training data model.
It is not possible to learn
It is possible to learn larger
larger and more complex
and more complex models
models than with supervised
with unsupervised learning.
Complex model learning.
Model We can test our model. We can not test our model.
Supervised learning is also Unsupervised learning is also
Called as called classification. called clustering.
Example: Optical character Example: Find a face in an
Example recognition. image.
Supervision supervised learning needs Unsupervised learning does
supervision to train the not need any supervision to
Supervised machine Unsupervised machine
Parameters learning learning
model. train the model.