0% found this document useful (0 votes)
5 views32 pages

MLT Unit-1 Introduction

Machine learning (ML) is a subset of artificial intelligence that enables computers to learn from data and make predictions without explicit programming. It addresses complex tasks, processes large data volumes, automates repetitive tasks, and personalizes user experiences across various industries such as healthcare, finance, and transportation. The document also outlines the history, types, and future trends of machine learning, highlighting its growing importance and applications.

Uploaded by

bt410324
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views32 pages

MLT Unit-1 Introduction

Machine learning (ML) is a subset of artificial intelligence that enables computers to learn from data and make predictions without explicit programming. It addresses complex tasks, processes large data volumes, automates repetitive tasks, and personalizes user experiences across various industries such as healthcare, finance, and transportation. The document also outlines the history, types, and future trends of machine learning, highlighting its growing importance and applications.

Uploaded by

bt410324
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Unit-1: Introduction to Machine Learning

Introduction to Machine Learning


Machine learning (ML) is a type of artificial intelligence (AI) that trains computer algorithms to find patterns
in data, learn from experience, and make decisions or predictions without being explicitly programmed for
each task, improving automatically as they process more data. Essentially, it's about teaching computers to
learn from examples, like recognizing a cat in a photo after seeing many labelled cat pictures, enabling
applications from recommendation engines to self-driving cars.

Why do we need Machine Learning?


Traditional programming requires exact instructions and doesn’t handle complex tasks like understanding
images or language well. It can’t efficiently process large amounts of data. Machine Learning solves these
problems by learning from examples and making predictions without fixed rules.

Key Reasons We Need Machine Learning:

1. Solving Complex Business Problems


Traditional programming struggles with tasks like language understanding and medical diagnosis. ML learns
from data and predicts outcomes easily.
Examples:
 Image and speech recognition in healthcare.
 Language translation and sentiment analysis.

2. Handling Large Volumes of Data


The internet generates huge amounts of data every day. Machine Learning processes and analyzes this data
quickly by providing valuable insights and real-time predictions.
Examples:
 Fraud detection in financial transactions.
 Personalized feed recommendations on Facebook and Instagram from billions of interactions.

3. Automate Repetitive Tasks


ML automates time-consuming, repetitive tasks with high accuracy hence reducing manual work and errors.
Examples:
 Gmail filtering spam emails automatically.
 Chatbots handling order tracking and password resets.
 Automating large-scale invoice analysis for key insights.

4. Personalized User Experience


ML enhances user experience by tailoring recommendations to individual preferences. It analyze user
behavior to deliver highly relevant content.
Examples:
 Netflix suggesting movies and TV shows based on our viewing history.
 E-commerce sites recommending products we're likely to buy.

5. Self Improvement in Performance


ML models evolve and improve with more data helps in making them smarter over time. They adapt to user
behavior and increase their performance.
Examples:
 Voice assistants like Siri and Alexa learning our preferences and accents.
 Search engines refining results based on user interaction.
 Self-driving cars improving decisions using millions of miles of driving data.

1|P a g e
Unit-1: Introduction to Machine Learning

How Does Machine Learning Work?


A machine "learns" by identifying patterns in data and improving its ability to perform specific tasks without
being explicitly programmed for every scenario. This learning process helps machines to make accurate
predictions or decisions based on the information they receive. Unlike traditional programming where
instructions are fixed, ML allows models to adapt and improve through experience.

Here is how the learning process works:


1. Data Input: Machine needs data like text, images or numbers to analyze. Good quality and enough
quantity of data are important for effective learning.
2. Algorithms: Algorithms are mathematical methods that help the machine find patterns in data.
Different algorithms help different tasks such as classification or regression.
3. Model Training: During training, the machine adjusts its internal settings to better predict outcomes.
It learns by reducing the difference between its predictions and actual results.
4. Feedback Loop: Machine compares its predictions with true outcomes and uses this feedback to
correct errors. Techniques like gradient descent help it update and improve.
5. Experience and Iteration: Machine repeats training many times with data helps in refining its
predictions with each pass, more data and iterations improve accuracy.
6. Evaluation and Generalization: Model is tested on unseen data to ensure it performs well on real-
world tasks.

Machines "learn" by continuously increasing their understanding through data-driven iterations like how
humans learn from experience.

Importance of Data in Machine Learning


Data is the foundation of machine learning (ML) without quality data ML models cannot learn, perform or
make accurate predictions.
 Data provides the examples from which models learn patterns and relationships.
 High-quality and diverse data improves how well models perform and generalize to new situations.
 It helps models to understand real-world scenarios and adapt to practical uses.
 Features extracted from data are important for effective training.
 Separate datasets for validation and testing measure how well the model works on unseen data.
 Data drives continuous improvements in models through feedback loops.

Applications of Machine Learning


Machine Learning is used in many industries to solve problems and improve services. Here are some
common real-world applications:

1. Healthcare: It helps doctors to diagnose diseases from medical images like X-rays and MRIs. It also
predicts patient outcomes and personalizes treatments which improves healthcare quality.
Examples: Medical image analysis, drug discovery, and patient risk prediction.

2|P a g e
Unit-1: Introduction to Machine Learning

2. Finance: In finance it detects fraudulent transactions in real time and supports algorithmic trading. It
also helps to assess credit risk helps in making lending safer and faster. Maximum financial processes
and improves fraud detection accuracy.
Examples: Credit scoring, algorithmic trading, fraud detection.

3. Retail and E-Commerce: It helps in personalized product recommendations and forecasts demand to
optimize inventory and also analyzes customer sentiment to improve shopping experiences. Enhances
customer experience, inventory management, and demand forecasting.
Example: Personalized recommendations, dynamic pricing, stock management.

4. Transportation and Automotive: Self-driving cars rely on ML to navigate and make decisions. It
optimizes delivery routes and predicts vehicle maintenance needs which reduces downtime. Improves
logistics, route optimization, and autonomous vehicle capabilities.
Examples: Self-driving cars, demand forecasting, fleet management.

5. Manufacturing: It improves quality control by detecting defects in products automatically and


predicts machine failures in advance and helps in production processes. Improve quality control,
predictive maintenance, and automation of production processes.
Example: Defect detection, equipment maintenance, and production automation.

6. Social Media and Entertainment: Platforms like Netflix and YouTube use ML to recommend
content we'll enjoy. It enables image and speech recognition for better user interaction. Makes
personalized content recommendations and enhances user experience.
Examples: Movie/music recommendations, content creation, and game personalization.

7. Education: Individualizes learning experiences, automates administrative tasks, and monitors student
progress.
Example: Adaptive learning platforms, grading automation, student analytics.

8. Agriculture: Automates crop management, forecasts yields, and monitors soil and plant health.
Example: Crop monitoring, pest detection, yield prediction.

9. Energy: Improves energy consumption forecasting and optimizes grid management.


Example: Smart grid management, consumption prediction, energy efficiency.

10. Security and Surveillance: Helps in face recognition, anomaly detection, and automatic monitoring.
Examples: Intrusion detection, CCTV monitoring, and access control.

Future Trends of Machine Learning


1. Generative AI
Generative AI models, such as GPT (for text) and diffusion models (for images), are gaining popularity to
generate content like text, images, audio, and even code.
These models are being applied across industries from marketing to entertainment for applications such as
content generation, design automation, and customized user experiences.

2. Edge Machine Learning


Edge ML uses machine learning models on end devices such as smartphones, IoT devices, or embedded
systems instead of cloud servers. This mitigates latency, enhances privacy, and facilitates improved real-
time decision-making in autonomous vehicles, smart home appliances, and wearable fitness monitors.

3. Blockchain
Blockchain, the system behind cryptos like Bitcoin, is helpful to many businesses. This technology applies
a decentralized ledger to document all transactions, thus ensuring transparency among the parties involved
3|P a g e
Unit-1: Introduction to Machine Learning

without any third party. Moreover, blockchain transactions are irreversible, meaning they can never be
erased or altered after updating the ledger.
Blockchain will likely combine with machine learning and AI since some features support each other in
both technologies. These features include a decentralized ledger, transparency, and immutability.

4. Explainable AI (XAI)
As ML models become increasingly sophisticated, the demand for transparency and interpretability
increases. Explainable AI aims to make human-understandable model decisions, solving ethical issues and
regulatory compliance in sensitive areas such as healthcare, finance, and legal systems.

5. Personalized AI Assistants & Search Engines


Today, everybody is quite familiar with personalized AI assistants like Siri and Alexa. These voice
assistants execute tasks like booking air tickets, bill payments, playing favorite songs, and even messaging
colleagues.
With time, these chatbots will also be able to offer even more personalized experiences, like providing
legal advice on all sorts of matters, making crucial business decisions, offering personalized medical
treatment, etc.

6. Self-Supervised Learning
This movement seeks to decrease the reliance on large labeled datasets by employing unlabeled data for
representation learning.
Self-supervised learning has been very promising in natural language processing (NLP), computer vision,
and speech recognition, and it is important for organizations with limited labeled data.

7. Personal Medical Devices


Today, wearable medical devices are already part of our routine. These devices monitor health metrics,
such as heart rate, glucose, salt, etc. However, with the mass adoption of machine learning and AI, such
devices will be able to provide much more information to users in the future.
Wearable devices will be capable of analyzing health information in real-time and giving personalized
diagnoses and treatments tailored to the needs of an individual. In serious cases, the wearable sensors can
also recommend a sequence of health tests based on health information. They can even schedule an
appointment with a specialist available in the vicinity.

8. Federated Learning
Federated learning enables models to be trained on decentralized devices while maintaining data
localization, ensuring privacy and security.
It's especially effective in sectors such as healthcare and finance, where data privacy is essential, but
collaborative learning is required.

4|P a g e
Unit-1: Introduction to Machine Learning

History of Machine Learning


Early Foundations (1940s-1950s)

 Philosophical Foundations
Aristotle introduced the concept of logical reasoning, suggesting that thought processes could follow
structured rules, similar to mechanical systems.
René Descartes later proposed that machines might replicate aspects of human thinking, hinting at the
possibility of intelligent systems.

 Early Computational Devices


Charles Babbage’s Analytical Engine and other early machines showcased the potential of devices
capable of performing complex calculations.

 First Neural Network (1943)


The first mathematical model of a neural network was introduced by Warren McCulloch and Walter
Pitts in 1943. Their work demonstrated that neurons could be represented mathematically and that neural
processes could be simulated by machines. Although limited, this model laid the groundwork for future
advancements in neural networks and shaped early research in ML.

 The Turing Test (1950)


In 1950, Alan Turing introduced the Turing Test, which evaluated a machine’s ability to exhibit human-
like intelligence.

Milestones in Machine Learning Development (1950-2000)

 Computer Checkers (1952)


The earliest machine learning program was introduced in the 1950s when Arthur Samuel,
an IBM employee and pioneer in the field of computer gaming and artificial intelligence, invented
a computer program that calculated the winning chance in checkers for each side.

 The Perceptron (1957)


In 1957, Frank Rosenblatt, an American psychologist at the Cornell Aeronautical
Laboratory introduced the Perceptron, a single-layer neural network model capable of recognizing
patterns. Rosenblatt’s Perceptron generated significant excitement as it demonstrated how machines could
learn from input data.

 Reinforcement Learning (1960)


By the early 1960s, an experimental "learning machine" with punched tape memory, called Cybertron, had
been developed by Raytheon Company to analyse sonar signals, electro-cardiograms, and speech patterns
using rudimentary reinforcement learning.

 Nearest Neighbor Algorithm (1967)


 A representative book on research into machine learning during the 1960s was Nils Nilsson's book
on Learning Machines, dealing mostly with machine learning for pattern classification.
 The development of the Nearest Neighbor algorithm in 1967 marked a significant step forward
in pattern recognition.
 Interest related to pattern recognition continued into the 1970s, as described by Duda and Hart in
1973.
 In 1981, a report was given on using teaching strategies so that an artificial neural network learns
to recognise 40 characters (26 letters, 10 digits, and 4 special symbols) from a computer terminal.

5|P a g e
Unit-1: Introduction to Machine Learning

 The Backpropagation Algorithm (1974)


The introduction of the backpropagation algorithm in 1974 was a turning point for neural networks.
Backpropagation allowed multi-layer networks to learn by correcting errors through feedback loops.

 The Stanford Cart (1979)


The Stanford Cart was a groundbreaking project in the field of autonomous vehicles. Developed in 1979,
the cart used ML algorithms to navigate obstacles in its environment without human intervention.

AI Winters & Renewed Interest (1970s-1990s)


 1970s: The first "AI Winter" sees reduced funding due to overblown promises.
 1980s: Explanation-Based Learning (EBL) emerges, and machines learn to pronounce words
(NetTalk).
 1990s: Focus shifts from knowledge-based to data-driven approaches; Convolutional Neural
Networks (CNNs) are developed for image recognition, as seen with Yann LeCun's work.

The Rise of Machine Learning (2000 – Present)

 Machine Defeats Man in Chess (1997)


Although technically before 2000, IBM’s Deep Blue made history by defeating Garry Kasparov, the
reigning world chess champion, in 1997. This event showcased the power of machine learning algorithms
in decision-making and pattern recognition

 The Torch Software Library (2002)


The release of Torch, an open-source software library, marked a significant shift in the development of
ML. Torch allowed researchers and developers to build machine learning models efficiently, driving
community-driven innovation.

 Deep Learning Breakthroughs (2006)


In 2006, Geoffrey Hinton and his team introduced breakthroughs in deep learning, enabling neural
networks to process large datasets more effectively. This advancement allowed for significant
improvements in fields such as speech recognition and computer vision, solidifying deep learning as a
powerful subset of ML.

 Google Brain (2011)


The launch of the Google Brain project applied machine learning to large-scale systems. Google used ML
to improve services such as search engines and advertising platforms, demonstrating how ML could
scale to handle enormous datasets.

 DeepFace (2014)
In 2014, Facebook introduced DeepFace, a facial recognition project that used deep learning to identify
faces with high accuracy. This technology demonstrated the practical applications of ML in biometric
security and image recognition.

 ImageNet Challenge (2017)


The ImageNet Challenge became a benchmark for evaluating ML models in computer vision. In 2017,
ML systems achieved human-level accuracy in recognizing objects, marking a major milestone in ML.
The success of ImageNet highlighted the capabilities of convolutional neural networks (CNNs) and deep
learning in advancing computer vision technologies.

 Generative AI (2010s Onwards)


The rise of generative AI models, such as GPT and DALL-E, transformed ML’s role in creative fields.
These models generate text, images, and even music, expanding ML’s applications beyond analytics and
predictions. Generative AI has opened new possibilities in fields like content creation, design, and
entertainment.

6|P a g e
Unit-1: Introduction to Machine Learning

 2017: The Transformer architecture is introduced, becoming the foundation for modern large
language models (LLMs) like ChatGPT.
 2022-Present: Release of ChatGPT sparks mainstream awareness and rapid innovation in
generative AI.

7|P a g e
Unit-1: Introduction to Machine Learning

Types of Machine Learning


There are several types of machine learning, each with special characteristics and applications. Some of the
main types of machine learning algorithms are as follows:
1. Supervised Machine Learning
2. Unsupervised Machine Learning
3. Reinforcement Learning

Additionally, there is a more specific category called Semi-Supervised Learning and Self-Supervised
Learning, which combines elements of both supervised and unsupervised learning.

1. Supervised learning
Supervised learning is a machine learning approach where the model is trained on a dataset containing input-
output pairs, known as labeled
data. The goal is for the model
to learn the relationship
between inputs and their
corresponding outputs so it can
accurately predict the output for
new, similar data.

Example: If you train a model


using labeled images of cats
and dogs, it learns the features
of each. When shown a new
image, it predicts whether it’s a
cat or a dog.

8|P a g e
Unit-1: Introduction to Machine Learning

Example: Consider the following data regarding patients entering a clinic. The data consists of the gender
and age of the patients and each patient is labeled as "healthy" or "sick".

Gender Age Label


M 48 sick
M 67 sick
F 53 healthy
M 49 sick
F 32 healthy
M 34 healthy
M 21 healthy

In this example, supervised learning is to use this labeled data to train a model that can predict the label
("healthy" or "sick") for new patients based on their gender and age. For example if a new patient i.e Male
with 50 years old visits the clinic, model can classify whether the patient is "healthy" or "sick" based on the
patterns it learned during training.

Where to Use Supervised Learning


 When you have labeled data and want to predict outcomes.
 Ideal for classification (like spam detection) or regression tasks (like price forecasting).
 Best used in domains where historical data with outcomes is already available.

Applications
Supervised learning is used in a wide variety of applications, including:
 Image, speech and text processing: For tasks like image classification, speech recognition and
sentiment analysis.
 Predictive analytics: To forecast sales, customer churn, stock prices and weather conditions.
 Recommendation and personalization: Powering systems that suggest products, movies or content.
 Healthcare and finance: Used for medical diagnosis, fraud detection and credit scoring.
 Automation and control: In autonomous vehicles, manufacturing quality checks and gaming AI.

2. Unsupervised learning:
Unsupervised learning works with unlabeled data where no correct answers or categories are provided. The
model's job is to find the data, hidden patterns, similarities or groups on its own. This is useful in scenarios
where labeling data is difficult or
impossible. It’s mainly used for
clustering, dimensionality
reduction and data visualization.

Example: If you have customer


data without labels, the
algorithm can group similar
customers based on purchase
behavior useful for
segmentation and marketing.
Example: Consider the following data regarding patients. The dataset has a unlabeled data where only the
gender and age of the patients are available with no health status labels.
Gender Age
M 48
M 67
F 53
M 49
F 34

9|P a g e
Unit-1: Introduction to Machine Learning

M 21
Here unsupervised learning looks for patterns or groups within the data on its own. For example it might
cluster patients by age or gender and grouping them into categories like "younger healthy patients" or "older
patients" without knowing their health status.

Where to Use Unsupervised Learning


 When data is unlabeled or unstructured.
 Useful for exploratory analysis, clustering or feature extraction.
 Common in marketing, recommendation systems and fraud detection where patterns matter more
than labels.

Applications of Unsupervised Learning


Here are some common applications of unsupervised learning:
 Clustering and segmentation: Group similar data points, customers or images.
 Anomaly detection: Spot unusual patterns or outliers in data.
 Dimensionality reduction: Simplify large datasets while retaining key information.
 Recommendation and marketing: Identify user preferences and improve product suggestions.
 Data preprocessing and analysis: Clean data, detect patterns and support exploratory data analysis
(EDA).

3. Reinforcement Learning
Reinforcement Learning (RL) trains an agent to make decisions by interacting with an environment. Instead
of being told the correct answers, agent learns by trial-and-error method and gets rewards for good actions
and penalties for bad ones. Over time it develops a strategy to maximize rewards and achieve goals. This
approach is good for problems having sequential decision making such as robotics, gaming and autonomous
systems.

Example: While Identifying a


Fruit, system receives an input for
example an apple and initially
makes an incorrect prediction like
"It's a mango". Feedback is
provided to correct the error
"Wrong! It's an apple" and the
system updates its model based on
this feedback.
Over time it learns to respond
correctly that "It's an apple" when
getting similar inputs and also
improves accuracy.

Types of Reinforcement Learning


 Positive Reinforcement: Rewards desired behavior (e.g., giving points for correct answers).
 Negative Reinforcement: Removes negative outcomes to encourage good actions (e.g., turning off
a buzzer after the right move).

Where to Use Reinforcement Learning


 When you need an agent to learn by interacting with an environment.
 Best for decision-making or optimization tasks involving trial and feedback loops.
 Used when long-term performance or adaptive behavior is more important than immediate accuracy.

Applications of Reinforcement Learning


Here are some applications of reinforcement learning:
 Gaming and simulation: Teaching agents or NPCs to play and adapt intelligently.
 Robotics and automation: Enabling robots to perform tasks autonomously.

10 | P a g e
Unit-1: Introduction to Machine Learning

 Autonomous vehicles: Helping self-driving cars make real-time decisions.


 Healthcare and finance: Optimizing treatment plans, trading and resource allocation.
 Recommendation and personalization: Improving user experience through adaptive suggestions.
 Industrial and energy management: Optimizing control systems and energy use.

Besides these three main types, modern machine learning also includes two other important approaches: Self-
Supervised Learning and Semi-Supervised Learning.

4. Semi-Supervised Learning
Semi-supervised learning is a hybrid machine learning approach which uses both supervised and
unsupervised learning. It uses a small amount of labelled data combined with a large amount of unlabelled
data to train models. The goal is to learn a function that accurately predicts outputs based on inputs, similar
to supervised learning, but with much less labelled data.

Where to Use Semi-Supervised Learning


 When you have limited labeled data but plenty of unlabeled data.
 Useful for domains with high labeling costs, such as medical, NLP or image datasets.
 Ideal when unlabeled data still holds valuable information that can improve learning performance.

Applications
 Image Classification: Combine small labeled and large unlabeled image datasets to improve
accuracy.
 Natural Language Processing (NLP): Enhance language models by using a mix of labeled and vast
unlabeled text data.
 Speech Recognition: Boost accuracy by leveraging limited transcribed audio and more unlabeled
speech data.
 Recommendation Systems: Improve recommendations using sparse labeled data and abundant
unlabeled user behavior.
 Healthcare & Medical Imaging: Improve medical image analysis with a mix of labeled and
unlabeled images.

5. Self-Supervised Learning
Self-Supervised Learning (SSL) is a type of machine learning where a model is trained using data that does
not have any labels or answers provided. Instead of needing people to label the data, the model finds patterns
and creates its own labels from the data automatically.
This allows the model to learn useful information by teaching itself from the data. SSL is especially useful
when there is a lot of data but only a small part of it is labelled or labelling the data would take a lot of time
and effort.

Real-life examples include GPT-3/4 predicting missing words in text, AI systems colorizing black-and-white
photos, and autonomous vehicles learning to navigate by predicting future video frames from raw sensor
data.

11 | P a g e
Unit-1: Introduction to Machine Learning

Where to Use Self-Supervised Learning


 When manual labeling is impossible or expensive.
 Suitable for large-scale datasets like text, audio and images.
 Best for pre-training models that can later be fine-tuned for specific supervised tasks.

Applications
 Natural Language Processing
 Computer Vision and Speech Recognition
 Video understanding
 Pre-training for large AI models

Comparison Table: Supervised vs Unsupervised vs Reinforcement Learning

Criteria Supervised Learning Unsupervised Learning Reinforcement Learning


Learns from labeled data Identifies patterns in Learns through interaction
Definition
unlabeled data with environment
Labeled data Unlabeled data No predefined data learn
Type of Data
from environment
Type of Classification, Clustering, Association Sequential decision-making
Problems Regression
Requires external No supervision No supervision, learns from
Supervision
supervision feedback
SVM, Decision Trees, K-Means, PCA, Q-learning, DQN, SARSA
Algorithms
Neural Networks Autoencoders
Predict outcomes Discover hidden patterns Optimize actions for
Goal
accurately maximum rewards
Medical diagnosis, fraud Customer segmentation, Self-driving cars, robotics,
Applications
detection anomaly detection gaming

Real-World Applications

Machine Learning Type Domain Examples


Healthcare Disease diagnosis like cancer detection
Supervised Learning Finance Loan approval, credit risk assessment
NLP Sentiment analysis, text classification
E-commerce Product recommendation, customer segmentation
Unsupervised Learning Cybersecurity Fraud detection, intrusion detection
Biology Gene classification, dimensionality reduction
Autonomous Driving Self-driving cars learning optimal driving behavior
Reinforcement Learning Robotics Training robots for automated assembly tasks
Gaming AI-driven strategy games like AlphaGo

12 | P a g e
Unit-1: Introduction to Machine Learning

Well Posed/Defined Learning Problem


The formal definition of Well posed learning problem is:

“A computer program is said to learn from experience E with respect to some class of tasks T and
performance measure P, it its performance at tasks in T, as measured by P, improves with experience E.”
- Tom M. Mitchell

Key features include:


 Task (T): A clear, well-defined objective the system aims to achieve (e.g., classification, regression,
controlling a robot).
 Performance Measure (P): A quantifiable metric used to measure, evaluate, and improve the
system's effectiveness, such as accuracy, precision, or mean squared error.
 Experience (E): Data, examples, or training instances that allow the model to learn and enhance its
capability over time.
 Improvement: The fundamental goal is that the model's ability to perform task 𝑇 increases as it gains
more experience 𝐸.

Certain examples that efficiently defines the well-posed learning problem are -
1. To better filter emails as spam or not
 Task - Classifying emails as spam or not
 Performance Measure - The fraction of emails accurately classified as spam or not spam
 Experience - Observing you label emails as spam or not spam

2. A checkers learning problem


 Task - Playing checkers game
 Performance Measure - percent of games won against opposer
 Experience - playing implementation games against itself

3. Handwriting Recognition Problem


 Task - Acknowledging handwritten words within portrayal
 Performance Measure - percent of words accurately classified
 Experience - a directory of handwritten words with given classifications

4. A Robot Driving Problem


 Task - driving on public four-lane highways using sight scanners
 Performance Measure - average distance progressed before a fallacy
 Experience - order of images and steering instructions noted down while observing a human driver

5. Fruit Prediction Problem


 Task - forecasting different fruits for recognition
 Performance Measure - able to predict maximum variety of fruits
 Experience - training machine with the largest datasets of fruits images

6. Face Recognition Problem


 Task - predicting different types of faces
 Performance Measure - able to predict maximum types of faces
 Experience - training machine with maximum amount of datasets of different face images

7. Automatic Translation of documents


 Task - translating one type of language used in a document to other language
 Performance Measure - able to convert one language to other efficiently
 Experience - training machine with a large dataset of different types of languages

13 | P a g e
Unit-1: Introduction to Machine Learning

Designing a Learning System


Designing a learning system in machine learning is a multi-step process that ensures the system is effective,
efficient, and adaptable to real-world challenges. Each stage builds on the previous one to create a robust
framework.

Key steps include defining the learning task (T), performance measure (P), and training experience (E), then
selecting the target function, its representation, and an appropriate approximation algorithm, followed by
deployment and ongoing monitoring.

Core Steps in Designing a Learning System

1. Define the Problem & Goals:


Clearly state what the system needs to achieve (the Task, T), how its success will be measured (Performance
Measure, P), and what data it will learn from (Training Experience, E).

2. Data Collection and Preparation


Data is the backbone of any learning system. Collecting and preprocessing high-quality, relevant data is
critical for the system’s success.
 Data Gathering: Data can come from databases, APIs, or real-time sensors. For instance, financial
forecasting may rely on stock market data, while medical systems use patient records.
 Data Preprocessing: Raw data often contains inconsistencies, missing values, and outliers. Use
techniques like imputation to handle missing values and normalization to scale features. Data
cleaning ensures the dataset is ready for training, minimizing errors caused by poor-quality data.

3. Choosing the Training Experience


The type of training experience chosen has a considerable amount of impact on our algorithm. The
training data’s characteristics need to be similar to that of the total data set’s characteristics.

In order to choose the right training experience for your algorithm, consider these three attributes,
a) Type of Feedback: Check whether the training experience provides direct or indirect feedback
to the algorithm based on the choices of the performance system. In Direct feedback, you get the
feedback of your choice immediately. In the case of indirect feedback, you get a sequence of
moves and the final outcome of the sequence of action.
b) Degree: The degree of a training experience refers to the extent up to which the learner can
control the sequence of training. For example, the learner might rely on constant feedback about
the moves played or it might itself propose a sequence of actions and only ask for help when in
need.
c) The representation of the distribution of samples across which performance will be tested is
the third crucial attribute. This basically means the more diverse the set of training experience
can be the better the performance can get.

Decide on the type of training experience based on the problem and the nature of the data:
 Supervised Learning: Best for tasks where labeled data is available, such as predicting loan defaults.
 Unsupervised Learning: Suitable for uncovering hidden patterns in unlabeled data, such as
clustering customers.
 Reinforcement Learning: Ideal for dynamic environments like robotics or gaming, where the system
learns through trial and error.

4. Feature Engineering & Selection


Identify and select the most relevant features (input variables) from the data that impact the outcome.

5. Choosing the Target Function


The target function defines the relationship between inputs (features) and desired outputs (predictions).

14 | P a g e
Unit-1: Introduction to Machine Learning

The nature of a target function depends on the type of machine learning problem that's being solved, and
whether the solution involves regression, binary classification, multiclass classification or more complex
nonlinear mappings.

Target function can be a:


 Linear regression. e.g., predicting house prices.
 Logistic regression. Binay classification e.g., spam vs. not spam.
 Decision trees. nonlinear, hierarchical structure
 Support vector machines. The model learns a decision boundary
 Neural networks. The model approximates complex, often nonlinear target functions using multiple
layers of interconnected nodes with activation functions.

6. Choosing a Representation for the Target Function


The representation of a target function in machine learning is the chosen model architecture (e.g., linear
regression, neural network, decision tree) used to approximate the ideal, unknown mapping from input
features to output targets. It defines the hypothesis space, translating raw data into a mathematical form that
the learning algorithm can optimize.

Choosing the appropriate representation for the target function depends on the problem’s complexity and
data characteristics:
 Decision Trees: Effective for hierarchical decision-making tasks.
 Neural Networks: Suitable for handling non-linear relationships in large, complex datasets.
 Linear Models: Best for interpretable, straightforward problems.

This step requires balancing model complexity with interpretability and computational efficiency.

7. Choosing a Function Approximation Algorithm


In this step, we choose a learning algorithm that can approximate the target function chosen. This step further
consists of two sub-steps, a. Estimating the training value, and b. Adjusting the weights.

Common Algorithms
Various machine learning algorithms are used for function approximation, including:
 Linear Regression: Uses a linear function to approximate the target function.
 Neural Networks (Deep Learning): Can model complex non-linear relationships. They learn
features automatically from data through algorithms like backpropagation and gradient descent.
 Support Vector Machines (SVMs): Can be used for both classification and regression
 Decision Trees: Can approximate discrete-valued or continuous target functions by using a set of
rules (yes/no questions) to partition the input space.
 Basis Function Methods: Transform the input data into a higher-dimensional feature space where
the function approximation problem might be easier to solve (e.g., using Radial Basis Functions or
tile coding)

8. Training the Model

Train the chosen model using the prepared data. This involves:
 Feed the prepared data to the algorithm to train the model

 Estimating training values:


Estimating training values in machine learning involves determining the optimal parameters (weights
and biases) of a model by minimizing a loss function or maximizing a reward function during training.

 Adjusting the weights


Adjusting weights in machine learning is the core training process where model parameters (numeric
values) are iteratively updated to minimize error between predictions and actual targets. Using

15 | P a g e
Unit-1: Introduction to Machine Learning

algorithms like Gradient Descent and Backpropagation, the model scales input features to determine
their importance, effectively "learning" by strengthening or weakening connections.

9. Evaluating Model Performance


Evaluating the model ensures it generalizes well to new data. Use techniques such as:
 Validation Splits: Dividing the data into training, validation, and test sets.
 Cross-Validation: Techniques like k-fold cross-validation provide a more robust evaluation by
rotating the training and testing datasets.
 Analyze metrics such as:
 Accuracy for classification tasks.
 Mean Squared Error (MSE) for regression problems.
 ROC-AUC for binary classification performance.

10. Iterative Refinement


Refining the model is a continuous process aimed at improving its performance:
 Hyperparameter Tuning: Adjust parameters like learning rate, depth of decision trees, or the number
of layers in neural networks.
 Retraining with Updated Data: Incorporate new or additional data to enhance the model’s
understanding of the problem domain.
 Reevaluating Performance: Regularly assess the model using updated validation datasets to ensure
consistent improvements.
This iterative cycle ensures the learning system evolves, adapting to changing data and requirements while
achieving optimal performance.

11. The Final Design


In machine learning, the final design is the completed, end-to-end architecture of a learning system,
implemented after refining the model through data, training, and evaluation.
It integrates four main components—performance system, critic, generalizer, and experiment generator—to
allow a system to autonomously improve, predict, and adapt to new, unseen data.

Key aspects of the final design include:


 Performance System: Executes the actual task, such as playing a game or making a prediction, using
the learned target function.
 Critic: Analyzes the performance system's output (successes/failures) and generates training
examples.
 Generalizer: Creates a hypothesis (an estimation of the target function) based on the training
examples provided by the critic.
 Experiment Generator: Takes the hypothesis and generates new, challenging problems to maximize
the learning rate and improve future performance.

The final design is developed after several iterative steps, including data collection, preprocessing, feature
selection, and model training. It represents the fully matured, operational system capable of handling real-
world scenarios, such as in the classic example of designing a checkers-playing machine.

16 | P a g e
Unit-1: Introduction to Machine Learning

Introduction to Machine Learning Approaches


There are mainly three approaches to work in machine learning. These are:
1. Supervised Machine Learning
i. Classification
(a) Linear Classification
(b) Non-Linear Classification
ii. Regression
2. Unsupervised Machine Learning
i. Clustering
3. Reinforcement Machine Learning

1. Classification
Classification in machine learning is a supervised learning technique that categorizes input data into
predefined classes or labels based on trained patterns. It predicts categorical outcomes (e.g., "spam" or
"not spam") rather than continuous values, making it essential for tasks like spam filtering, image
recognition, and medical diagnosis.
For instance, an algorithm can learn to predict whether a given email is spam or ham (no spam), as
illustrated below.

Types of Classification Problems


There are different types of classification problems depending on how many categories (or classes) we are
working with and how they are organized.
1. Binary Classification: Two possible outcomes, such as true/false, yes/no, or spam/not spam.
2. Multi-Class Classification: More than two distinct classes, such as classifying images as cat, dog,
or bird.

3. Multi-Label Classification: Each instance can be assigned multiple labels simultaneously. A movie
recommendation system could tag a movie as both action and comedy.

17 | P a g e
Unit-1: Introduction to Machine Learning

Classification Algorithms
There are various types of classifiers algorithms. Some of them are:
i) Linear Classifiers: Linear classifier models create a linear decision boundary between classes. They
are simple and computationally efficient. Some of the linear classification models are as follows:
 Logistic Regression
 Support Vector Machines having kernel = 'linear'
 Single-layer Perceptron
 Stochastic Gradient Descent (SGD) Classifier

ii) Non-Linear Classifiers: Non-linear models create a non-linear decision boundary between classes.
They can capture more complex relationships between input features and target variable. Some of the
non-linear classification models are as follows:
 K-Nearest Neighbours
 Kernel SVM
 Naive Bayes
 Decision Tree Classification
 Ensemble learning classifiers:
 Random Forests,
 AdaBoost,
 Bagging Classifier,
 Voting Classifier,
 Extra Trees Classifier
 Multi-layer Artificial Neural Networks

Examples of Machine Learning Classification in Real Life


Classification algorithms are widely used in many real-world applications across various domains, including:
 Email spam filtering: Filters our emails into spam or not spam based on email content.
 Credit risk assessment: Algorithms predict whether a loan applicant is likely to default by analyzing
factors such as credit score, income and loan history. This helps banks make informed lending
decisions and minimize financial risk.
 Medical diagnosis: Machine learning models classify whether a patient has a certain condition like
cancer or diabetes based on medical data such as test results, symptoms and patient history. This aids
doctors in making quicker, more accurate diagnoses, improving patient care.
 Image classification: Applied in fields such as facial recognition, autonomous driving and medical
imaging.
 Sentiment analysis: Determining whether the sentiment of a piece of text is positive, negative or
neutral. Businesses use this to understand customer opinions, helping to improve products and
services.
 Fraud detection: Algorithms detect fraudulent activities by analyzing transaction patterns and
identifying anomalies crucial in protecting against credit card fraud and other financial crimes.
 Recommendation systems: Used to recommend products or content based on past user behavior, such
as suggesting movies on Netflix or products on Amazon. This personalization boosts user satisfaction
and sales for businesses.

2. Regression
Regression in machine learning is a supervised learning technique used to predict continuous numerical
outcomes by modeling the relationship between dependent (target) and independent (predictor)
variables. It fits a line or curve to data, minimizing errors to forecast trends like prices, sales, or
temperature.
It helps understand how changes in one or more factors influence a measurable outcome and is widely
used in forecasting, risk analysis, decision-making and trend estimation.
 Works with real-valued output variables
 Helps to identify strengths and the type of relationships
 Supports both simple and complex predictive models.
 Used for tasks like price prediction, trend forecasting and risk scoring.

18 | P a g e
Unit-1: Introduction to Machine Learning

Types of Regression
Regression can be classified into different types based on the number of predictor variables and the
nature of the relationship between variables:

 Linear Regression: Models a linear relationship between input and output.


 Polynomial Regression: Models non-linear relationships by raising independent variables to a
power.
 Ridge/Lasso Regression: Regularization techniques that reduce overfitting by penalizing large
coefficients.
 Decision Tree Regression: Uses a tree-like structure to predict numerical values, good for non-
linear, complex data.

Applications
 Predicting prices: Used to predict the price of a house based on its size, location and other features.
 Forecasting trends: Model to forecast the sales of a product based on historical sales data.
 Identifying risk factors: Used to identify risk factors for heart patient based on patient medical
data.
 Making decisions: It could be used to recommend which stock to buy based on market data.

3. Clustering
Clustering is an unsupervised machine learning technique that automatically groups unlabeled data
points into clusters based on shared similarities or patterns, such as distance, density, or statistical
distribution. It is used for pattern recognition, customer segmentation, image processing, and anomaly
detection by organizing data into meaningful, homogeneous groups without pre-existing labels.

For example, if we have customer purchase data, clustering can group customers with similar shopping
habits. These clusters can then be used for targeted marketing, personalized recommendations or customer
segmentation.

Types of Clustering
Let's see the types of clustering,
i. Hard Clustering: In hard clustering, each data point strictly belongs to exactly one cluster, no overlap
is allowed. This approach assigns a clear membership, making it easier to interpret and use for definitive
segmentation tasks.
ii. Soft Clustering: Soft clustering assigns each data point a probability or degree of membership to
multiple clusters simultaneously, allowing data points to partially belong to several groups.
19 | P a g e
Unit-1: Introduction to Machine Learning

Types of Clustering Methods


Clustering methods can be classified on the basis of how they form clusters,
Common Clustering Algorithms:
 K-Means Clustering: Partitions data into K distinct clusters based on centroids, with data points
assigned to the nearest centroid.
 Hierarchical Clustering: Builds a tree-like structure (dendrogram) of clusters, either top-down or
bottom-up.
 DBSCAN (Density-Based Spatial Clustering of Applications with Noise): Identifies clusters
based on the density of points, effectively finding arbitrary shapes and handling noise/outliers.

Applications of Clustering:
 Customer Segmentation: Grouping customers by purchasing behavior for targeted marketing.
 Anomaly Detection: Identifying outliers in fraud detection or network security.
 Image Segmentation: Dividing images into distinct regions based on pixel similarities.
 Document Classification: Clustering documents or news articles by topic.

4. Reinforcement Machine Learning


Reinforcement learning (RL) is a machine learning technique where an autonomous agent learns to make
decisions by trial and error, interacting with an environment to maximize long-term rewards. Unlike
supervised learning, it does not require labeled data but learns from consequences (positive/negative
feedback) to establish an optimal strategy.

Types of Reinforcement Learning


 Value-based: The agent aims to maximize a value function, which determines the long-term value
of being in a state.
 Policy-based: The agent directly learns the policy, mapping states to the best possible actions.
 Model-based: The agent creates a model of the environment to simulate and plan actions.

Applications of Reinforcement Learning


 Robotics: Training robots to perform complex tasks through trial and error.
 Autonomous Vehicles: Self-driving cars navigating traffic.
 Game Playing: AI systems like AlphaGo or Atari-playing bots.
 Resource Management: Optimizing industrial processes and data center energy.

Key Differences between Regression, Classification, Clustering

Feature Regression Classification Clustering


Learning Type Supervised Supervised Unsupervised
Output Type Continuous (Numbers) Discrete (Labels) Group Labels
Labels Required Yes Yes No
Goal Predict a value Classify data Find patterns/groups
Example House price prediction Spam detection Customer segmentation

 Relationship: Regression and Classification are similar in that they both use training data with
known labels to make predictions, while Clustering relies on input data only to find patterns.

20 | P a g e
Unit-1: Introduction to Machine Learning

Issues / Challenges in Machine Learning


Despite its potential, machine learning faces several challenges that can affect model performance and limit
its real-world applicability.

1. Data Issues:
o Poor Quality/Noisy Data: Poor-quality data, which may be incorrect, incomplete, missing, noisy, or
inconsistent, can lead to inaccurate predictions and flawed outcomes. Data preprocessing is a crucial
step to ensure that data is clean and ready for analysis.
o Data Bias: Bias in machine learning refers to systematic errors where an algorithm produces skewed,
unfair, or inaccurate results, often due to flawed or prejudiced data, incorrect assumptions, or human
biases during development, leading to poor performance or discrimination, especially against
marginalized groups.
o Insufficient Data: Machine learning models require large amounts of high-quality, labelled data to
learn effectively. However, in many domains, obtaining such data is difficult due to factors like privacy
concerns, costs of data collection, and data sparsity. When the training dataset is too small, models can
struggle to capture meaningful patterns, resulting in poor performance on unseen data. This problem
becomes particularly pronounced in fields like healthcare, where collecting large, diverse datasets is
challenging.
o Imbalanced Datasets: Occurs when one class of data is significantly more prevalent than another,
causing the model to perform poorly on the minority class.

2. Model Performance:
o Overfitting: Overfitting occurs when a machine learning model becomes too complex and fits the
noise in the training data rather than the underlying patterns. This results in poor generalization to new
data. Overfitting is caused by models with too many or irrelevant parameters, or when there is
insufficient regularization.
o Underfitting: The model is too simple to capture the underlying patterns in the data. Underfitting
occurs when the model is too simple or lacks the capacity to capture complex patterns.
o Model Drift and Continuous Monitoring: Over time, changes in the data distribution can lead to
model performance degradation, a phenomenon known as model drift. Once a machine learning model
is deployed, continuous monitoring is essential to ensure that it remains accurate and relevant. Models
require periodic updates and retraining to ensure they continue to deliver accurate predictions as new
data becomes available.

3. Technical and Ethical Challenges:


o Lack of Interpretability/Explainability: Many machine learning models, especially deep
learning models, are often described as “black boxes” due to the difficulty in understanding how they
make decisions, reducing trust. This lack of explainability presents challenges in industries where
transparency is crucial, such as healthcare and finance.
o Computational Intensity: Computational complexity issues in machine learning (ML) arise from the
substantial time and memory resources required to train and run models, particularly as dataset (data
size, n) and model sizes (features, f) increase. These issues directly impact the scalability, feasibility,
and efficiency of ML applications.
o Security Risks: Security risks involve protecting the ML system, model, and data from intentional,
malicious attacks (e.g., hacking, data poisoning). Vulnerability to adversarial attacks that can
manipulate model predictions. Balancing accuracy with privacy remains a persistent challenge.
o Development and Performance: The development of machine learning models can be complex,
requiring expertise in data preprocessing, model selection, and hyperparameter tuning. Scaling these
processes for larger datasets or diverse use cases adds to the challenge. Implementing machine learning
models and obtaining actionable results can be a slow process, particularly for complex algorithms or
large datasets.
o Deployment and Maintenance: Deploying ML models into production is more complex than training
them. Integration with APIs, databases and real-time systems often introduces compatibility and
performance challenges.
21 | P a g e
Unit-1: Introduction to Machine Learning

4. Operational Challenges:
o Lack of Skilled Resources: Machine Learning isn’t just about algorithms it requires deep
understanding of the domain to interpret results correctly. Without domain insight, even accurate
models can lead to poor business decisions. The demand for skilled machine learning professionals far
exceeds the available supply, creating a skills gap that slows the adoption of machine learning
technologies.
o Privacy and Legal Issues: Machine Learning models often rely on sensitive user data, creating risks
around data leaks, misuse or non-compliance with laws. Privacy issues focus on individual rights
regarding how personal data is collected, used, and shared (e.g., in training data). Legal issues centre
on compliance with regulations (like GDPR, CCPA) governing data handling, algorithmic fairness, and
intellectual property.
o Rapid Technological Evolution and Skill Gaps: ML technology evolves rapidly, making it difficult
for professionals to stay up to date. New tools, frameworks and models appear faster than teams can
adapt, creating significant skill gaps

Comparison to AI, DS, DL, ML


Artificial Intelligence (AI) is the broad, overarching field aimed at enabling machines to simulate human
intelligence, with Machine Learning (ML) as a subset focused on learning from data, and Deep
Learning (DL) as a subset of ML using neural networks for complex tasks. Data Science (DS) is a
multidisciplinary field utilizing these technologies to extract insights from structured/unstructured data.

Key Differences and Relationship:


 Artificial Intelligence (AI): The ultimate goal—creating systems that act, think, or make decisions
like humans (e.g., robotics, expert systems).

 Machine Learning (ML): Techniques that allow machines to learn from data to improve predictions
without being explicitly programmed (e.g., linear regression, decision trees).

 Deep Learning (DL): A specialized subset of ML, using multi-layered neural networks (ANN, CNN,
RNN) to process complex data like images and text, mimicking the human brain.

 Data Science (DS): Uses data to gain insights, combining ML, statistics, and domain expertise. It is
often broader than just building models, focusing on data analysis, visualization, and interpretation.

22 | P a g e
Unit-1: Introduction to Machine Learning

Comparison Table

AI (Artificial ML (Machine DL (Deep DS (Data


Feature
Intelligence) Learning) Learning) Science)
Neural-
Simulates
network Extracts insights
Definition human Learns from data
based from data
intelligence
learning
Scope Broad (Goal) Subset of AI Subset of ML Multidisciplinary
Massive,
Structured &
Data Type All types Structured/Unstructured mostly
Unstructured
unstructured
Data
Low to high Medium to high Very High High
Requirements
High-
Mimic human Learn from data to accuracy Derive actionable
Goal
intelligence predict complex insights
learning
Neural
Logic, Rules, Statistical models, Analytics, Stats,
Method Networks
Algorithms algorithms Visualization
(deep)
Complexity Moderate Medium High Medium
Intelligent Data insights Actionable
Output Accurate prediction
decision (insights) Insights/Reports
Autonomous Image Customer churn
Example Fraud detection
vehicles recognition analysis
Tools / IBM Watson, TensorFlow, Scikit- Keras, Python, R,
Frameworks Google AI Learn PyTorch Tableau

Core Interactions:
 Data Science provides the data and insights necessary to build intelligent models.
 AI applications are realized through ML and DL algorithms.
 Deep Learning is used for the most complex, unstructured data tasks within the broader context
of Data Science and AI.

23 | P a g e
Unit-1: Introduction to Machine Learning

Types of Datasets in Machine Learning


In machine learning, datasets can be categorized in several ways: by their structure (structured,
unstructured, semi-structured), by the type of data they contain (numerical, categorical, etc.), and by
their purpose in the machine learning workflow (training, validation, testing).

By Data Structure
This classification focuses on how data is organized and stored.
 Structured Datasets: Data is organized in a fixed, tabular format with clearly defined rows and
columns, similar to a spreadsheet or relational database table. This format is easy to query and
analyze.
o Examples: Financial records, customer databases, inventory systems.
 Unstructured Datasets: This data lacks a predefined format or schema and is stored in its native
form. It often requires more sophisticated tools for processing and analysis.
o Examples: Text documents (emails, reports), images, audio recordings, and videos.
 Semi-structured Datasets: This type falls between the two extremes, incorporating some markers
or syntax for organization but not following a rigid schema.
o Examples: JSON, XML, and HTML files used in web applications and APIs.

By Data Type (Features)


This classification is based on the nature of the individual data points or features within the dataset.
 Numerical Datasets: Contain quantitative data that can be measured or counted.
o Continuous Data: Can take any value within a given range (e.g., height, weight, temperature).
o Discrete Data: Can only take specific, countable values, usually whole numbers (e.g., number
of students, shoe size).
 Categorical Datasets: Contain qualitative data that represents discrete categories or groups.
o Nominal Data: Categories have no intrinsic order or ranking (e.g., gender, hair color, blood
group).
o Ordinal Data: Categories have a meaningful order or rank, but the difference between values
is not quantifiable (e.g., customer ratings, education levels).
 Time Series Datasets: Records data points over a sequence of time, allowing for the tracking of
trends and changes (e.g., stock prices, sensor data).
 Image Datasets: Consist of images used for tasks like classification, object detection, or
segmentation.
 Text (NLP) Datasets: Comprise textual data used for tasks such as sentiment analysis, machine
translation, or text classification.

By Purpose in ML Workflow
In the practical application of machine learning, a single dataset is typically split into three subsets for
different stages of model development.
 Training Data: The largest portion of the data used to train the machine learning model, where the
model learns the relationships and patterns between features and target outcomes.
 Validation Data: A subset used during the training phase to tune model hyperparameters and prevent
overfitting (when a model performs well on training data but poorly on new data).
 Testing Data: A separate, unseen subset of data used to evaluate the final model's performance and
accuracy on new, real-world examples.

24 | P a g e
Unit-1: Introduction to Machine Learning

Model Evaluation and Metrics


Evaluation metrics are essential in machine learning to measure how well a model performs on a given
dataset. They provide a standardized way to assess the effectiveness of models, helping data scientists decide
whether a model is ready for deployment or needs further improvement. Without appropriate evaluation
metrics, selecting the best model for a specific task would be challenging. For instance, metrics like accuracy,
precision, or mean squared error allow us to quantify performance, enabling better decision-making.

The choice of evaluation metrics depends on the specific problem domain, the type of data, and the desired
outcome. Evaluation metrics can vary depending on the type of problem: classification or regression, or
clustering.

Classification Metrics
Classification metrics evaluate models that predict discrete outcomes, such as determining whether an email
is spam or not. These metrics help assess how well the model distinguishes between different classes.

In classification problems, we use two types of algorithms (dependent on the kind of output it creates):
1. Class output: Algorithms like SVM and KNN create a class output. For instance, in a binary
classification problem, the outputs will be either 0 or 1. However, today we have algorithms that can
convert these class outputs to probability. But these algorithms are not well accepted by the statistics
community.
2. Probability output: Algorithms like Logistic Regression, Random Forest, Gradient Boosting,
Adaboost, etc., give probability outputs. Converting probability outputs to class output is just a matter
of creating a threshold probability.

To evaluate the performance of classification models, we use the following metrics:

1. Confusion Matrix
Confusion matrix is a table that summarizes the performance of a classification model. It’s particularly useful
for visualizing the predicted vs. actual (true) outcomes. Confusion matrix creates a N X N matrix, where N
is the number of classes or categories that are to be predicted. Here we have N = 2, so we get a 2 X 2 matrix.

A confusion matrix provides a comprehensive overview of a model’s


predictions, breaking them down into:
 True Positives (TP): It is the case where we predicted Yes and
the real output was also Yes.
 True Negatives (TN): It is the case where we predicted No and
the real output was also No.
 False Positives (FP) – Type 1 Error: It is the case where we
predicted Yes but it was actually No.
 False Negatives (FN) – Type 2 Error: It is the case where we
predicted No but it was actually Yes.

Suppose there is a problem with our practice which is a binary classification. Samples of that classification
belong to either Yes or No. So, we build our classifier which will predict the class for the new input sample.
After that, we tested our model with 165 samples and we get the following result.

n=165 Actual Yes Actual No


Predicted Yes 100 (TP) 10 (FP)
Predicted No 5 (FN) 50 (TN)

Benefits of Confusion Matrices


 Beyond Accuracy: While accuracy is a simple metric, a confusion matrix gives a more detailed
picture of the types of errors your model is making.

25 | P a g e
Unit-1: Introduction to Machine Learning

 Handles Class Imbalance: If your dataset is imbalanced, a confusion matrix helps uncover whether
the model is biased towards predicting the majority class, even if the accuracy might seem deceptively
high.
 Calculating Multiple Metrics: It is extremely useful for measuring precision-recall, Specificity,
Accuracy, and most importantly, AUC-ROC curves.

Practical Example — Spam Detection


Imagine a spam detection classifier:
 A high number of false positives means numerous legitimate emails are going to spam.
 A high number of false negatives means a lot of spam still reaches the inbox.

2. Accuracy
Accuracy is one of the simplest metrics. It measures the percentage of correctly predicted labels out of the
total predictions.
Formula:

Or

(True Positives + True Negatives)


Accuracy = (True Positives + True Negatives + False Positives + False Negatives)

Example: Fraud Detection


Imagine a dataset with 99% non-fraudulent transactions and only 1% fraudulent cases. A model that always
predicts “non-fraud” would have a 99% accuracy, yet be completely useless in practice!

Limitations
Sensitive to class imbalance: Accuracy can be misleading when working with imbalanced datasets. For
example, in a dataset with 90% class A and 10% class B, a model predicting only class A will still achieve
90% accuracy but it will fail to identify any class B instances.

Strengths
 Easy to understand: It has a straightforward interpretation.
 Good for balanced classes: When your dataset has roughly equal proportions of each class, accuracy
is a suitable overall performance indicator.

When to use Accuracy


 When your classes are relatively balanced in the dataset.
 When you want a general overall picture of how well the model performs don’t focus on specific
types of errors (false positives vs. false negatives).

3. Precision
Precision indicates the proportion of correctly predicted positive results out of all predicted positive results.
It’s crucial when minimizing false positives is more important than capturing all positives, such as in spam
detection or financial fraud analysis.
Formula:

Example: If a spam filter correctly identifies 80 spam emails but incorrectly flags 20 non-spam emails as
spam, the precision is 80 / (80 + 20) = 80%.

26 | P a g e
Unit-1: Introduction to Machine Learning

Focus: Precision tells you how reliable the model is when it says something is positive. A high-precision
model is less likely to produce false alarms.

When to Use Precision:


 When false positives have a higher cost than false negatives.
 When you want to be very confident in the model’s positive predictions.
 Consider your context and weigh the trade-off between precision and recall.

4. Recall (Sensitivity)
Recall or Sensitivity measures how many of the actual positive cases were correctly identified by the model.
It is important when missing a positive case (false negative) is more costly than false positives.
Formula:

In scenarios where catching all positive cases is important (like disease detection), recall is a key metric.

Example: If a model detects 90 out of 100 actual spam emails, its recall is 90 / (90+10) = 90%.

Focus: Recall reflects how good your model is at not missing out on the class you are truly interested in. A
high recall model minimizes false negatives.

When to Use Recall:


 When the cost of a false negative is much higher than a false positive.
 When you want to prioritize catching as many cases of the positive class as possible.
 Consider the context and the trade-offs between recall and precision.

5. F1 Score
The F1 Score is the harmonic mean of precision and recall. It is useful when we need a balance between
precision and recall as it combines both into a single number. A high F1 score means the model performs
well on both metrics. Its range is [0,1].
Lower recall and higher precision give us great accuracy but then it misses a large number of instances. More
the F1 score better will be performance. It can be expressed mathematically in this way:

Example: For a model with precision of 80% and recall of 70%, the F1 score is (2 x 0.8 x 0.7) / (0.8 + 0.7)
= 74.3

When to Use F1-Score


 Imbalanced Classes: When your dataset has an unequal distribution of classes, the F1-score is a
better performance indicator than accuracy.
 When Precision and Recall both matter: Use it when you don’t want to solely focus on minimizing
either false positives or false negatives and seek a balance between the two.
 Comparing models: The F1-score helps in comparing models that might have different trade-offs
between precision and recall.

Intuition:
 Balances Precision and Recall: The F1-score provides a single metric that considers both. A high
F1-score implies a model that is good at both classifying positive cases correctly (precision) and
finding most of the positive cases (recall).

27 | P a g e
Unit-1: Introduction to Machine Learning

 Penalizes Imbalance: Because it’s a harmonic mean, the F1-Score becomes low if either precision
or recall is low.

6. Logarithmic Loss (Log Loss)


Log loss measures the uncertainty of the model’s predictions. It is calculated by penalizing the model for
assigning low probabilities to the correct classes. This metric is used in multi-class classification and is
helpful when we want to assess a model’s confidence in its predictions. If there are N samples belonging to
the M class, then we calculate the Log loss in this way:

Where:
 𝑦𝑖𝑗 =Actual class (0 or 1) for sample 𝑖 and class 𝑗
 𝑝𝑖𝑗 =Predicted probability for sample 𝑖 and class 𝑗
The goal is to minimize Log Loss, as a lower Log Loss shows higher prediction accuracy.

7. Area Under the Curve (AUC) – Receiver Operating Characteristic (ROC)

AUC-ROC measures the model’s ability to distinguish between positive and negative classes across various
threshold levels. It is useful for binary classification tasks. The AUC value represents the probability that the
model will rank a randomly chosen positive example higher than a randomly chosen negative example. AUC
ranges from 0 to 1 with higher values showing better model performance.

Key Components:

(i) True Positive Rate (TPR)


Also known as sensitivity or recall, the True Positive Rate measures how many actual positive instances
were correctly identified by the model. It answers the question: "Out of all the actual positive cases, how
many did the model correctly identify?"
Formula:
TP
TPR =
TP + FN
Where:
 TP = True Positives (correctly predicted positive cases)
 FN = False Negatives (actual positive cases incorrectly predicted as negative)
(ii) True Negative Rate (TNR)
Also called specificity, the True Negative Rate measures how many actual negative instances were correctly
identified by the model. It answers the question: "Out of all the actual negative cases, how many did the
model correctly identify as negative?"
Formula:
TN
TNR =
TN + FP
Where:
 TN = True Negatives (correctly predicted negative cases)
 FP = False Positives (actual negative cases incorrectly predicted as positive)

(iii) False Positive Rate (FPR)


It measures how many actual negative instances were incorrectly classified as positive. It’s a key metric when
the cost of false positives is high such as in fraud detection.
Formula:
FP
FPR =
FP + TN
Where:

28 | P a g e
Unit-1: Introduction to Machine Learning

 FP = False Positives (incorrectly predicted positive cases)


 TN = True Negatives (correctly predicted negative cases)

(iv) False Negative Rate (FNR)


It measures how many actual positive instances were incorrectly classified as negative. It answers: "Out of
all the actual positive cases, how many were misclassified as negative?"
Formula:
FN
FNR =
FN + TP
Where:
 FN = False Negatives (incorrectly predicted negative cases)
 TP = True Positives (correctly predicted positive cases)

Interpretation:
 AUC = 1: Perfect classification.
 AUC = 0.5: No discrimination (random guessing).
 AUC between 0.5 and 1: Has some ability to discriminate between classes.
 AUC < 0.5: Model performs worse than random guessing (showing that the model is inverted).

ROC Curve
It is a graphical representation of the True Positive Rate (TPR) vs the False Positive Rate (FPR) at different
classification thresholds. The curve helps us visualize the trade-offs between sensitivity (TPR) and specificity
(1 - FPR) across various thresholds. Area Under Curve (AUC) quantifies the overall ability of the model to
distinguish between positive and negative classes.

Axes:
 X-axis: False Positive Rate (FPR) = 1 — Specificity (Measures how often a negative instance is
wrongly classified as positive.)
 Y-axis: True Positive Rate (TPR) = Recall (Measures how many of the positive cases the model
catches.)

How it’s created:


 Calculate TPR and FPR at various classification thresholds (decision boundary).
 Plot each point (FPR, TPR)
 Connect the points to form the ROC curve.

Why use ROC-AUC


 Handles Class Imbalance: ROC-AUC is robust to imbalanced classes since it focuses on the
model’s ability to rank positives correctly rather than raw accuracy.
 Threshold Invariant: It shows performance across all thresholds, helping choose the ideal threshold
later based on your specific context.
 Clear interpretation: AUC has a probabilistic interpretation, making it easier to understand
compared to some other metrics.

Example:
Imagine two models that detect disease:
 Model A has a higher accuracy but a lower AUC than Model B.
 The ROC curve reveals that Model B is better at ranking the patients likely to have the disease even
if it might misclassify a few more individuals overall.

29 | P a g e
Unit-1: Introduction to Machine Learning

Regression Metrics
Regression metrics are used to evaluate machine learning models that predict continuous outcomes, such as
housing prices, stock values, or sales forecasts. These metrics measure the difference between the predicted
and actual values to determine how well a model performs in regression tasks. Below is a detailed explanation
of the most commonly used regression metrics.

1. Mean Absolute Error (MAE)


MAE measures the average magnitude of errors in a set of predictions, without considering their direction.
It represents the average absolute difference between predicted values and actual values.

Formula:

Where:

Example: If the actual values are [3, 5, 7] and the predicted values are [2, 5, 8], the MAE is:

Limitation:
It gives a clear view of the model’s prediction accuracy but it doesn't shows whether the errors are due to
over- or under-prediction. It is simple to calculate and interpret helps in making it a good starting point for
model evaluation.

2. Mean Squared Error (MSE)


MSE calculates the average of the squared differences between the predicted and actual values. Squaring the
differences ensures that larger errors are penalized more heavily helps in making it sensitive to outliers. This
is useful when large errors are undesirable but it can be problematic when outliers are not relevant to the
model’s purpose.

Formula:

30 | P a g e
Unit-1: Introduction to Machine Learning

Where:
 𝑦𝑗 = Actual value
 𝑦̂𝑗 = Predicted value

3. Root Mean Squared Error (RMSE)


RMSE is the square root of MSE, bringing the metric back to the original scale of the data. Like MSE, it
heavily penalizes larger errors but is easier to interpret as it’s in the same units as the target variable. It’s
useful when we want to know how much our predictions deviate from the actual values in terms of the same
scale.
Formula:

Where:
 𝑦𝑗 = Actual value
 𝑦̂𝑗 = Predicted value

Example: Using the same values as above, the RMSE is:

4. Root Mean Squared Logarithmic Error (RMSLE)


RMSLE calculates the square root of the logarithmic differences between predicted and actual values. It
penalizes under-predictions more than over-predictions, making it suitable for targets with large ranges.

Formula:

or

Where:
 𝑦𝑗 = Actual value
 𝑦̂𝑗 = Predicted value

Use Case: RMSLE is often used in scenarios like sales forecasting, where large variations in the target
variable exist.

5. R² (R-squared)
R2 score represents the proportion of the variance in the dependent variable that is predictable from the
independent variables. An R² value close to 1 shows a model that explains most of the variance while a value
close to 0 shows that the model does not explain much of the variability in the data. R² is used to assess the
goodness-of-fit of regression models.
Formula:

Where:
 𝑦𝑗 = Actual value
 𝑦̂𝑗 = Predicted value
 𝑦ˉ= Mean of the actual values

31 | P a g e
Unit-1: Introduction to Machine Learning

Example: An R2 score of 0.85 means the model explains 85% of the variance in the target variable.

Use Case: It’s widely used in linear regression and serves as a quick measure of model performance.

6. Adjusted R² Score
The adjusted R² score modifies the R² score to account for the number of predictors in the model, preventing
overfitting.
Formula:

 N: Number of observations.
 k: Number of predictors.

Use Case: Essential for evaluating models with multiple features or predictors.

7. Mean Bias Deviation (MBD)


MBD calculates the average bias in predictions, showing whether the model tends to over-predict or under-
predict.
Formula:

Use Case: It’s a diagnostic metric to identify systemic bias in predictions.

Clustering Metrics

In unsupervised learning tasks such as clustering, the goal is to group similar data points together. Evaluating
clustering performance is often more challenging than supervised learning since there is no explicit ground
truth. However, clustering metrics provide a way to measure how well the model is grouping similar data
points.

1. Silhouette Score
Silhouette Score evaluates how well a data point fits within its assigned cluster considering how close it is
to points in its own cluster (cohesion) and how far it is from points in other clusters (separation). A higher
silhouette score (close to +1) shows well-clustered data while a score near -1 suggests that the data point is
in the wrong cluster.
Formula:

Where:
 a = Average distance between a sample and all other points in the same cluster
 b = Average distance between a sample and all points in the nearest cluster

2. Davies-Bouldin Index
Davies-Bouldin Index measures the average similarity between each cluster and its most similar cluster. A
lower Davies-Bouldin index shows better clustering as it suggests the clusters are well-separated and
compact. The goal is to minimize the Davies-Bouldin index to achieve optimal clustering.
Formula:

Where:
 𝜎𝑖 = Average distance of points in cluster i from the cluster centroid
 𝑑(𝑐𝑖 , 𝑐𝑗 ) = Distance between centroids of clusters i and j
By mastering the appropriate evaluation metrics, we upgrade ourselves to fine-tune machine learning models
which helps in ensuring they meet the needs of diverse applications and deliver optimal performance.

32 | P a g e

You might also like