0% found this document useful (0 votes)
2 views221 pages

Python With Machine Learning Training - Delegate Pack

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)
2 views221 pages

Python With Machine Learning Training - Delegate Pack

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

theknowledgeacademy

Python with Machine


Learning
theknowledgeacademy

Course Syllabus
• Module 1: Introduction to Machine Learning
• Module 2: Regression
• Module 3: Classification
• Module 4: Unsupervised Learning
• Module 5: Dimensionality Reduction
• Module 6: Deep Learning
theknowledgeacademy
Description

Module 1 1 What is Machine Learning?

2 Python for Machine Learning

3 AI vs Machine Learning
Introduction to Machine
Learning
4 Classification of Machine Learning

5 Supervised vs Unsupervised Learning

6 Reinforcement Learning
theknowledgeacademy
Description

Module 1 7 Datasets for ML

8 Popular Sources of ML Datasets

9 Kaggle Datasets
Introduction to Machine
Learning
10 UCI Machine Learning Repository

11 Datasets via AWS

12 Google’s Datasets Search Engine


theknowledgeacademy
Description

Module 1 13 Microsoft Datasets

14 Computer Vision Datasets

15 Scikit-learn Datasets
Introduction to Machine
Learning
16 Application of Machine Learning

17 Virtual Process Assistance

18 Email Spam and Malware Filtering


theknowledgeacademy
Description

Module 1 19 Traffic Prediction

20 Image Recognition

21 Speech Recognition
Introduction to Machine
Learning
22 Product Recommendation

23 Self-Driving Car

24 Detection Online Frauds


theknowledgeacademy
Description

Module 1 25 Python libraries for Machine Learning

26 Numpy

27 Pandas
Introduction to Machine
Learning
28 Matplotib

29 Scikit-learn
theknowledgeacademy
Description

Module 1 30 Scipy

31 Tensorflow

32 Pytorch
Introduction to Machine
Learning
33 Keras
What is Machine Learning?
✓ Machine Learning (ML) is a subset of artificial intelligence that focuses on the development of algorithms and statistical models that enable computers to
theknowledgeacademy

perform specific tasks without explicit instructions.

✓ Instead, these systems learn and make decisions based on data. At its core, ML is about recognizing patterns in data and then applying these patterns to

predict future outcomes or behaviours.

✓ This ability to learn from data allows machines to improve their performance overtime, adapting to new scenarios without human intervention. The

applications of machine learning are vast and varied, ranging from self-driving cars and speech recognition systems to medical diagnosis and financial

forecasting.

✓ Machine learning techniques are pivotal in handling large and complex data sets, making them invaluable in an era where data is increasingly crucial for

decision-making and innovation. As we advance, ML continues to push the boundaries of what machines can achieve, reshaping industries and enhancing

human capabilities.
Python for Machine Learning
✓ Python is a preferred programming language for Machine Learning due to its simplicity and readability, making it accessible to beginners and experts alike.
theknowledgeacademy

✓ It boasts a rich ecosystem of libraries such as NumPy for numerical computations, pandas for data manipulation, and scikit-learn for machine learning

algorithms, which streamline the development process.

✓ Python's versatility allows it to integrate seamlessly with other technologies and platforms, enhancing its utility in handling diverse datasets and

performing complex analyses.

✓ This integration is crucial in deploying machine learning models efficiently across different production environments. Additionally, Python's community

support is unmatched; the vast array of tutorials, forums, and documentation available makes troubleshooting and learning an ongoing, community-

supported process.

✓ This strong community and robust framework support make Python an ideal choice for developing sophisticated machine learning models that require

scalability and integration flexibility.


AI vs Machine Learning
✓ Here’s a comparison of AI and Machine Learning presented in a table format to highlight their differences:
theknowledgeacademy

Aspect Artificial Intelligence (AI) Machine Learning (ML)

AI is the broader concept of machines designed to mimic ML is a subset of AI focused on algorithms that enable
Definition human intelligence, involving reasoning, speech recognition, machines to learn from data and make decisions without
and decision-making. being explicitly programmed.

AI includes any technology that enables machines to mimic ML is specifically focused on algorithms and statistical
Scope
human behavior. models that allow machines to perform specific tasks.

AI systems can be rule-based, handling specific structured ML systems learn from data to improve their performance
Functionality
scenarios, or they can be adaptive and designed for learning. over time without human intervention.

ML is primarily used in systems that require continual


AI is used in a range of applications from expert systems to
Applications learning and adaptation, such as predictive analytics and
natural language processing and more.
data mining.

AI can function without ongoing data input for certain ML requires large volumes of data from which to learn and
Dependence on Data
applications that rely on pre-set rules and logic. make predictions or decisions.

Learning Capability Not all AI systems have the ability to learn; some are designed ML inherently involves learning from data, improving
to respond according to predefined rules. accuracy over time based on input data and experience.
Classification of Machine Learning
✓ The following are the classifications of machine learning:
theknowledgeacademy

1. Supervised Learning: This is the most prevalent form of machine learning, where the model is trained on a labeled dataset. Here, the input data comes
with corresponding output labels, and the model learns to predict the output from the input data. Common applications include spam detection, risk
assessment, and customer segmentation.

2. Unsupervised Learning: In unsupervised learning, the model deals with unlabeled data. The goal here is to infer the underlying structure from the input
data. Common techniques include clustering and association to find patterns and relationships in data. Examples include customer segmentation based on
purchase behavior and social media analysis.

3. Semi-supervised Learning: This approach falls between supervised and unsupervised learning. It uses a small amount of labeled data along with a larger
amount of unlabeled data. It's useful when labeling data becomes costly or impractical, and it helps improve learning accuracy with limited labeled data.

4. Reinforcement Learning: In this type, the learning process is driven by rewards. Algorithms learn to achieve a goal in complex, uncertain environments by
understanding the actions that produce the best rewards. Applications include robotics, gaming strategy, and real-time decision making.

5. Deep Learning: While technically a subset of machine learning, deep learning deserves mention due to its unique capabilities with large data sets and its
power in fields like computer vision and natural language processing. It involves neural networks with many layers, hence the "deep" nomenclature.
Supervised vs Unsupervised Learning
✓ The following are the difference between Supervised vs Unsupervised Learning:
theknowledgeacademy

Aspect Supervised Learning Unsupervised Learning


Unsupervised learning involves training a model on data
Supervised learning involves training a model on known input
Definition without pre-existing labels, letting the model find patterns and
and output data so that it can predict future outputs.
relationships on its own.
Uses unlabeled datasets where only the input data is provided,
Uses labeled datasets where both the inputs and the correct
Data and the algorithms must infer the structures from the data
outputs are provided.
itself.
Common algorithms include clustering (e.g., k-means,
Common algorithms include linear regression, logistic regression,
Algorithms hierarchical), association rule mining, and principal component
and support vector machines (SVM).
analysis (PCA).
Used for prediction (e.g., predicting prices or classifying emails as Used for discovering the inherent structure of data, like
Applications
spam or not spam). grouping customers by purchasing behavior.

Learning from the model is done through feedback given to the No explicit feedback is provided to the model. The learning
Feedback
model about the accuracy of predictions during training. process is based on the data's intrinsic properties.
Example A spam filter that learns to flag emails as spam based on A customer segmentation tool that groups similar customers
observing user corrections when it misclassifies emails. together based on shopping data without knowing in advance
any group definitions.
Reinforcement Learning
✓ Reinforcement Learning (RL) is a type of machine learning where an agent learns to make decisions by performing actions in an environment to maximize
theknowledgeacademy

some notion of cumulative reward.

✓ This learning process is based on the interaction between the agent and the environment, rather than being supervised by explicitly provided correct

answers. The following are some key points about Reinforcement Learning:

1. Agent and Environment: In RL, an agent interacts with its environment by taking actions and receiving feedback in the form of rewards that guide its

learning.

2. Goals and Rewards: The agent’s main goal is to maximize the total reward it receives over time. This reward is a signal that tells the agent what is

beneficial and what is detrimental within the environment.


Reinforcement Learning
3. Decisions and Policies: The agent makes decisions based on a policy, which is a strategy that the agent follows to determine the next action based on its
theknowledgeacademy

current state.

4. Exploration vs. Exploitation: RL involves a trade-off between exploration (trying new things to find out what yields the most reward) and exploitation

(using known information to garner the most reward).

5. Learning and Planning: RL can be used for both learning optimal policies and planning by using models of the environment.

6. Applications: Reinforcement learning is widely used in various applications such as robotics for autonomous navigation, game playing (e.g., AlphaGo), and

decision-making in finance and healthcare.

7. Algorithms: Common RL algorithms include Q-learning, Deep Q Networks (DQN), Policy Gradient methods, and Actor-Critic methods.
Datasets for ML
✓ Datasets play a crucial role in machine learning (ML) as they provide the raw material from which
theknowledgeacademy

models learn and extract insights. Datasets for ML can be broadly categorized based on their content,

structure, and purpose, ranging from text and images to complex structured data for regression or

classification tasks.

Types of Datasets:

1. Structured Data: Comprises clearly defined data types whose pattern makes them easily searchable

(e.g., SQL databases, Excel spreadsheets).

2. Unstructured Data: Consists of data that is not as easily searchable, including text, video, images, and

social media postings.

3. Semi-structured Data: A type of structured data that does not conform to formal structure of data

models but contains tags to separate data elements (e.g., XML, JSON).
Datasets for ML
✓ The following are the steps that how to download the dataset for ML:
theknowledgeacademy

Step 1: Click and open the providd link: [Link]

Step 2: Click on Download


Datasets for ML
Step 3: Now, click on Sign in with Google. Enter the email ID and click Next
theknowledgeacademy
Datasets for ML
Step 4: Enter the password and click Next, then click on Download
theknowledgeacademy
Datasets for ML
Step 5: Again, click on Download dataset as zip. The dataset will automatically be downloaded as a ZIP folder to your system, Now extract the dataset according
theknowledgeacademy

to your requirements
Datasets for ML
Step 6: Once downloaded, you can load the dataset into Python using pandas. Run the code and then see the output
theknowledgeacademy
Datasets for ML
✓ A dataset is the collection of data is arranged in some order.
theknowledgeacademy

✓ A data can be numerical data, categorical data or ordinal data.


✓ Any machine learning project's technology cannot function properly if the dataset is not well-prepared and pre-processed.
✓ The datasets are completely relied upon by the developers as they work on the ML project.
✓ The datasets used to create ML applications are split into two categories:
• Training dataset
• Test Dataset
Datasets for ML
✓ Training Dataset:
theknowledgeacademy

✓ Training data set is the large data set used to teach a machine learning model.

✓ Training data set used to teach prediction models that use machine learning algorithms to extract features that are relevant to specific

business goals.

✓ Train data set is a subset to train a model to find the specific output.
Datasets in ML
✓ Testing dataset:
theknowledgeacademy

✓ The test data set is another subset of original data, which is not dependent on the train data set.

✓ A well-organized dataset called test data contains information for each type of scenario the model might encounter in the real world. The

test dataset for an ML project typically makes up 20–25% of the total original data.
Popular Sources of ML Datasets
Kaggle Datasets
theknowledgeacademy

UCI machine learning Repository

Datasets via AWS

Google Dataset Search Engine

Microsoft Datasets

Awesome Public Datasets

Computer vision Datasets

Scikit-learn Datasets
UCI Machine Learning Repository
✓ The UCI Machine Learning Repository is a widely used resource for machine learning practitioners and researchers. It offers a large collection
theknowledgeacademy

of datasets that are freely available for studying and analyzing various machine learning problems. Here’s a brief introduction to the UCI
Machine Learning Repository:

1. Established Resource: The Repository is hosted by the University of California, Irvine and has been an active resource since its inception in
1987. It is one of the oldest sources of dataset collections.

2. Diverse Datasets: It contains datasets from a broad range of domains including business, education, science, and social sciences. This
diversity makes it an invaluable resource for testing algorithms across different types of data and applications.

3. Accessibility: All datasets in the repository are accessible for free. Each dataset comes with a detailed description, including information
about the data, attributes, and sometimes insights into potential uses.
UCI Machine Learning Repository
4. Educational Tool: It serves as a significant educational tool in machine learning and data science courses, providing practical hands-on
theknowledgeacademy

experience to students.

5. Research and Experimentation: Researchers and developers use these datasets to compare algorithm performance, conduct statistical
tests, and publish new research, making it a cornerstone of the machine learning community.

6. Contribution and Update: Individuals and organizations are encouraged to contribute their datasets to the repository to help enrich the
available resources. The repository is regularly updated with new datasets.

7. Integration with Tools: Many machine learning and data analysis tools have direct methods to access and utilize datasets from the UCI
repository, simplifying the process of data retrieval and experimentation.
UCI Machine Learning Repository
✓ One of the best places to find machine learning datasets is the UCI Machine Learning Repository. The machine learning community
theknowledgeacademy

frequently uses this repository to store databases, domain theories, and data generators for use in analysing ML algorithms.
✓ It has been widely used as a primary source of machine learning datasets by students, professors, and researchers since the year 1987.

✓ Steps:
Step 1: Navigate to the given link : [Link]
Step 2: Click on View DATASETS > Heart Disease
UCI Machine Learning Repository
Step 3: Click on IMPORT IN PYTHON. Copy the command and run on the jupyter notebook
theknowledgeacademy
UCI Machine Learning Repository
Step 4: Now, copy the second code and again run on the notebook
theknowledgeacademy
Datasets via AWS
✓ AWS (Amazon Web Services) provides a comprehensive platform for hosting and sharing datasets, especially those that require large-scale
theknowledgeacademy

computing resources to process.


✓ The platform facilitates access to public datasets through the AWS Registry of Open Data, which encourages developers, researchers, and
businesses to experiment and develop solutions using this data without the need for local storage or computational capabilities.
✓ AWS offers a variety of tools and services to efficiently handle, analyze, and process datasets of any scale. With AWS, users can leverage
services such as Amazon S3 for storage, Amazon EC2 for compute power, and AWS Lambda for running code in response to events.
✓ AWS's integration with machine learning and data analysis tools supports advanced data processing workflows, enabling users to derive
valuable insights from large datasets quickly.
✓ The accessibility of AWS's public datasets allows for an easy start in many domains such as geospatial analysis, life sciences, and machine
learning, providing a rich resource pool that supports innovation and accelerates development in various scientific and business fields.
✓ This approach not only democratizes data access but also enhances collaborative efforts to solve complex problems using the power of cloud
computing.
Google’s Datasets Search Engine
✓ Google's Dataset Search Engine was officially launched in September 2018. It began as a beta version, providing users with access to millions
theknowledgeacademy

of datasets across various subjects and industries. The tool was designed to help researchers, scientists, data journalists, and data
enthusiasts find the data they need for their work more easily.

Step 1: Navigate to the given URL [Link]


Step 2: Enter the type of data you are interested in into the search bar, such as climate data
Google’s Datasets Search Engine
Step 3: Click on the URL located above the Explore at option
theknowledgeacademy

Step 4: Scroll down the page and click on the Explore button, then click Download. The file will automatically download
Google’s Datasets Search Engine
Step 5: Enter the code and run it. The output will display successfully.
theknowledgeacademy

Output

Example
Microsoft Datasets
✓ Microsoft provides a rich repository of datasets that are accessible through various services like Azure and GitHub. These datasets cater to a
theknowledgeacademy

wide range of industries and are particularly tailored for developers and data scientists to use in building and testing machine learning
models and applications. The datasets offered by Microsoft cover numerous domains such as natural language processing, computer vision,
and predictive analytics.
✓ For instance, the Azure Open Datasets platform features datasets that are pre-prepared for machine learning models and are integrated
directly into Azure ML tools for easy access and use. Microsoft’s commitment to empowering developers and businesses is evident in their
provision of these datasets.
✓ They not only support academic research and educational purposes but also enhance enterprise applications by providing real-world data
that can drive innovation and improve decision-making processes.
✓ Moreover, Microsoft fosters a community-driven approach by allowing contributors to share their datasets on platforms like GitHub,
promoting an environment of collaboration and continuous learning. This helps in maintaining a vibrant ecosystem where developers can
find a vast array of resources for their projects.
Computer Vision Datasets
✓ Computer vision datasets are extensive collections of images and sometimes videos that are used to train and evaluate algorithms in the
theknowledgeacademy

field of computer vision. These datasets are crucial for developing and benchmarking machine learning models that interpret and
understand visual information from the world. Here's a closer look at the key aspects of computer vision datasets:

1. Diversity and Volume: Computer vision datasets typically contain a large number of images to ensure that the models trained on them can
generalize well to new, unseen data. Diversity in the dataset helps in building robust models capable of understanding various scenes,
objects, and conditions.

2. Annotations and Labels: Most computer vision datasets come with annotations. These annotations can include labels for classification,
bounding boxes for object detection, or pixel-level segmentation masks for tasks like semantic segmentation. The quality and precision of
these annotations directly affect the performance of trained models.
Computer Vision Datasets
3. Use Cases: These datasets are used across a variety of applications such as facial recognition, autonomous driving, medical image analysis,
theknowledgeacademy

and many more. Each application requires different kinds of data and annotations based on the specific tasks, like detecting pedestrians or
diagnosing diseases.

4. Public Availability: There are numerous publicly available datasets that researchers and developers use to train and test algorithms.
Examples include ImageNet for image classification, COCO (Common Objects in Context) for object detection and segmentation, and more
specialized datasets like LIDAR datasets for autonomous vehicles.

5. Challenges: Working with these datasets involves challenges related to handling large volumes of data, ensuring the privacy and ethical use
of the images, and dealing with biased data which might affect the fairness of the models.
Computer Vision Datasets
Example Code:
theknowledgeacademy
Scikit-learn Datasets
✓ Scikit-learn provides a variety of datasets that are essential for machine learning projects. These datasets are available as small built-in
theknowledgeacademy

datasets, real-world datasets from repositories, and tools to generate synthetic datasets for custom needs. They are designed to support
learning, experimentation, and development of machine learning algorithms.

✓ Code Examples for Using Scikit-learn Datasets


1. Loading Built-in Datasets
Scikit-learn Datasets
2. Fetching Real-World Datasets
theknowledgeacademy
Scikit-learn Datasets
3. Generating Synthetic Datasets
theknowledgeacademy
Application of Machine Learning
theknowledgeacademy

1 Virtual personal assistance Email spam and malware filtering 2

3 Traffic congestion analysis and predictions


Image Recognition 4

5 Speech Recognition Product recommendation 6

7 Self-driving car Detection of online frauds 8


Virtual Process Assistance
✓ We have a variety of virtual personal assistants, including Siri, Cortana, Alexa, and Google Assistant.
theknowledgeacademy

✓ They assist us in finding the information using our voice commands, as the name suggests.
✓ Our voice commands to these assistants, such as "Play music," "Call someone," "Open an email," and "Schedule an appointment," among
others, can help us in a variety of ways.
✓ Machine learning algorithms are a key component of these virtual assistants.
✓ These assistants capture our voice commands, transmit them via a cloud server, decode them using ML algorithms, and then respond as
necessary.
Email Spam and Malware Filtering
✓ Every new email that we get is automatically classified as important, common, or spam. Machine learning is the technology that enables us
theknowledgeacademy

to consistently receive important emails marked with the important symbol in our inbox and spam emails in our spam box.
✓ Some spam filters used by Gmail are like content filter, header filter, permission filter etc.
✓ For email spam filtering and malware detection, some machine learning algorithms are used, including Multi-Layer Perceptron, Decision
tree, and Nave Bayes classifier.
Traffic Prediction
✓ When we want to travel to a new location, Google Maps comes in handy because it shows us the best route and anticipates traffic
theknowledgeacademy

conditions.
✓ It uses two methods to predict the state of the traffic, including whether it is clear, moving slowly, or jam-packed:
❑ Real-time vehicle location provided by sensors and the Google Maps app
❑ On similar days in the past, the average time was taken.
✓ Everyone who uses Google Map contributes to its improvement. In order to boost performance, it receives data from the user and sends it
back to its database.
Image Recognition
✓ One of the most popular uses of machine learning is image recognition. It is used to identify things like digital images, people, places, and
theknowledgeacademy

objects. Automatic friend tagging recommendation is a common application of image recognition and face detection.
✓ Facebook offers us an automatic friend tagging suggestion feature. The face detection and recognition algorithm used in machine learning is
what gives us an automatic tagging suggestion with names whenever we upload a photo of one of our Facebook friends.
✓ It is based on the "Deep Face" project from Facebook, which handles face recognition and person identification in photos.
Image Recognition
✓ Below is the example code:
theknowledgeacademy
Speech Recognition
✓ When using Google, we have the option to "Search by voice," which falls under speech recognition and is a well-known machine learning
theknowledgeacademy

application.
✓ Speech recognition, also known as "Speech to text" or "Computer speech recognition," is the process of turning spoken instructions into
text.
✓ Speech recognition applications currently use machine learning algorithms extensively. Speech recognition technology is used by Alexa,
Google Assistant, Siri, Cortana, and Microsoft Cortana to carry out voice commands.
Product Recommendation
✓ Amazon, Netflix, and other e-commerce and entertainment businesses frequently use machine learning to recommend products to users.
theknowledgeacademy

✓ Because of machine learning, whenever we search for a product on Amazon, we begin to see advertisements for that same product while
using the same browser to browse the internet.
✓ Google uses a variety of machine learning algorithms to understand user interests and makes product recommendations based on those
interests.
✓ Similar to this, machine learning is also used to recommend TV shows, movies, and other entertainment options when we use Netflix.
Self Driving Car
✓ Self-driving cars are one of the most intriguing uses of machine learning.
theknowledgeacademy

✓ Self-driving cars heavily rely on machine learning. The most well-known automaker, Tesla, is developing a self-driving vehicle.
✓ In order to train the car models to recognise people and objects while driving, unsupervised learning was used.
Detection Online Frauds
✓ By identifying fraudulent transactions, machine learning makes our online transactions safe and secure.
theknowledgeacademy

✓ Every time we conduct an online transaction, there may be a number of ways for a fraudulent transaction to occur, including the use of
fictitious accounts and identification documents and the theft of money in the middle of a transaction.
✓ In order to identify this, Feed Forward Neural Network assists us by determining whether the transaction is legitimate or fraudulent.
✓ Machine learning makes our online transactions safe and secure by identifying fraudulent transactions. There are a variety of ways for a
fraudulent transaction to happen every time we make an online purchase, including the use of fictitious accounts and identification
documents, as well as the theft of money in the middle of a transaction.
✓ Feed Forward Neural Network assists us in identifying this by determining whether the transaction is legitimate or fraudulent.
Python libraries for Machine Learning
theknowledgeacademy

1. NumPy 2. Scipy

3. Pandas 4. TensorFlow

5. Matplotlib 6. PyTorch

7. Scikit-learn 8. Keras
Numpy
theknowledgeacademy

• NumPy is a fundamental package for scientific


computing in Python, providing support for
large, multi-dimensional arrays and matrices,
along with a large collection of high-level
mathematical functions to operate on these
arrays. It is widely used in academia, finance,
and industry for fast and efficient numerical
operations.
Pandas
theknowledgeacademy

• Pandas is a powerful Python library widely


used for data manipulation and analysis. It
provides robust, easy-to-use data structures
like DataFrames and Series, making it an
essential tool for data scientists and analysts
working in Python
Matplotlib
theknowledgeacademy

• Matplotlib is a comprehensive library for


creating static, interactive, and animated
visualizations in Python. It provides a wide
array of functions and tools to produce high-
quality plots and charts, making it an
essential tool for data visualization in
scientific computing.
Scikit-learn
theknowledgeacademy

• Scikit-learn is a powerful Python library for


machine learning, providing a wide range of
supervised and unsupervised learning algorithms
via a consistent interface. It is widely used for data
mining and data analysis, built on top of NumPy,
SciPy, and matplotlib.
Scipy
theknowledgeacademy

• SciPy is a powerful Python library used


extensively in scientific and technical
computing. It builds on NumPy, providing a
large collection of algorithms and high-level
commands for data manipulation, signal
processing, optimization, and more, enabling
complex scientific calculations.
Tensorflow
theknowledgeacademy

• TensorFlow is an open-source machine learning


library developed by Google, primarily used for
deep learning applications. It offers flexible and
comprehensive tools, libraries, and community
resources that let researchers innovate with
machine learning, and productionize AI easily.
Pytorch
theknowledgeacademy

• PyTorch is an open-source machine learning library


developed by Facebook's AI Research lab, widely
used for applications such as computer vision and
natural language processing. It is known for its
flexibility and speed in building and training neural
network models, primarily through a technique
called automatic differentiation.
Keras
theknowledgeacademy

• Keras is a powerful and user-friendly neural


network library written in Python, designed to
enable fast experimentation with deep neural
networks. It acts as an interface for the
TensorFlow library, streamlining the process of
building and training complex models with
fewer lines of code..
theknowledgeacademy
Description

Module 2 1 Introduction to Regression

2 Writing
Why dofiles
wewith open
use Regression Analysis?

Loading data with Pandas


3 Regression Analysis-Related Terminologies

Regression

4 Types of Regression

5 Linear Regression

6 Linear Regression Formula


theknowledgeacademy
Description

Module 2 7 Types of Linear Regression

8 Writing
Linear files with open
Regression Line

Loading data with Pandas


9 Polynomial Regression

Regression

10 Non-Linear Regression

11 Model Evaluation Process

12 Cross Validation in ML
theknowledgeacademy
Description

Module 2 13 Methods Used for Cross-Validation

14 Writing files
Types of with open
Predictive Model

Loading data with Pandas


15 Confusion Matrix

Regression

16 Area Under the ROC Curve (AUC-ROC)

17 ROC Curve
theknowledgeacademy
Description

Module 2 18 AUC Curve

19 Writing files with


Application open Curve
of AUC-ROC

Loading data with Pandas


20 Mean Squared Error (MSE)

Regression

21 Root Mean Squared Error (RMSE)

22 K-fold Cross Validation


Introduction to Regression
✓ Regression is a technique for figuring out how independent variables relate toward a dependent variable.
theknowledgeacademy

✓ Regression is a set of mathematical techniques used in machine learning that let data scientists forecast a continuous outcome (y) based on the

value of one or more predictor variables (x)

✓ Regression mainly used for prediction, forecasting, time series modelling, and determining the casual-effect relationship between variables.

✓ Linear regression is the most popular form of regression analysis because of its simplicity in predicting and forecasting.
Why do we use Regression Analysis?
✓ A continuous variable can be predicted with the aid of regression analysis.
theknowledgeacademy

✓ In the real world, there are many situations where we need to make predictions about the future, including those involving the weather, sales,

marketing trends, and other factors.

✓ In these situations, we need technology that can make predictions more precisely. Regression analysis, a statistical technique used in machine

learning and data science, is therefore necessary in this situation.

✓ Regression calculates the relationship between the independent variable and the target.

✓ It is employed to identify data trends.

✓ We can confidently identify the most important factor, the least important factor, and how each factor is affecting the other factors by running

the regression.
Regression Analysis-Related Terminologies
✓ Dependent Variable: The dependent variable in a regression analysis is the key element that we want to forecast or comprehend. It also goes by
theknowledgeacademy

the name target variable.

✓ Independent Variable: The term "independent variable," also known as a "predictor," refers to the elements that have an impact on the

dependent variables or that are employed to forecast their values.

✓ Outliers: An outlier is an observation that has a very low or very high value compared to other values that have been observed. An outlier should

be avoided as it might hurt the outcome.

✓ Multicollinearity: Multicollinearity is a condition where the independent variables have a higher correlation with one another than with other

variables. It shouldn't be included in the dataset because it causes issues when determining which variable has the greatest impact.

✓ Underfitting and Overfitting : Overfitting is a problem that occurs when our algorithm performs well with the training dataset but poorly with

the test dataset. Underfitting is the term used when an algorithm does not perform well even with training data.
Types of Regression
✓ Regressions come in a variety of forms, and they are used in data science and machine learning. The significance of each type varies depending
theknowledgeacademy

on the situation, but fundamentally, all regression techniques examine the impact of the independent variable on the dependent variables.

1 Linear Regression Logistic Regression 2

3 Support vector Regression Decision Tree Regression 4

5 Random forest Regression Polynomial Regression


6

Detection of online frauds


7 Face recognition
8
Linear Regression
✓ Linear regression is a statistical regression mainly used for predictive analysis.
theknowledgeacademy

✓ It is one of the most basic and straightforward algorithms, it uses regression to illustrate the relationship between continuous variables.

✓ It is applied to the machine learning regression problem. The term "linear regression" refers to a statistical method that displays a linear

relationship between the independent variable X-axis and the dependent variable Y-axis.

✓ Such linear regression is referred to as simple linear regression if there is only one input variable (x).

✓ Additionally, this type of linear regression is known as multiple linear regression if there are multiple input variables.
Linear Regression
✓ The following is an example to implement linear regression:
theknowledgeacademy
Linear Regression Formula
✓ Below is the mathematical equation for simple linear regression :
theknowledgeacademy

Y= aX+b
✓ Here, y= dependent variable(target variable)

✓ x= independent variable (predictor variable)

✓ a and b are the linear coefficients


Types of Linear Regression
✓ Linear Regression can be further classified into two types.
theknowledgeacademy

✓ Simple Linear Regression: A linear regression algorithm is referred to as simple linear regression if only one independent variable is used to

predict the value of a numerical dependent variable.

✓ Multiple Linear Regression: A linear regression algorithm is referred to as multiple linear regression if it uses more than one independent

variable to forecast the value of a numerical dependent variable.


Linear Regression Line
✓ A Linear line showing the relationship between the dependent and independent variable is known as the line of regression.
theknowledgeacademy

✓ There are two types of relationship in regression line:

• Positive Linear Relationship: A relationship is referred to as positive linear if the dependent variable increases on the Y-axis and the

independent variable increases on the X-axis.

• Negative Linear Relationship: A relationship is referred to as negative linear if the dependent variable decreases on the Y-axis and the

independent variable increases on the X-axis.


Polynomial Regression
✓ Polynomial Regression is a regression algorithm which models the relationship between a dependent(y) and independent variable(x) as nth
theknowledgeacademy

degree polynomial.

✓ The equation of polynomial regression is given below:

y= b0+b1x1+ b2x12+ b2x13+...... bnx1n

✓ It is also known as the Multiple Linear Regression Special Case in Machine Learning because in order to transform the equation for multiple linear

regression into polynomial regression, you just need to add some polynomial terms.

✓ The training dataset for polynomial regression is non-linear in nature.


Polynomial Regression
✓ The following is an example to implement polynomial regression:
theknowledgeacademy
Non-Linear Regression
✓ Polynomial regression includes non-linear regression.
theknowledgeacademy

✓ A non-linear relationship between the dependent and independent variables is modelled using this technique.

✓ Since linear regression would not produce as accurate results as non-linear regression, it is used when the data exhibits a curved trend.

✓ The scatter plot highlights the nonlinear relationship between a nation's GDP over time. Instead of continuing along a straight line after 2005, the

line begins to curve. In these circumstances, a unique estimation technique known as non-linear regression is necessary.
Model Evaluation Process
✓ This evaluation technique helps to identify the algorithm that will deliver the expected results for the given dataset. Likewise, it is referred to as
theknowledgeacademy

"Best Fit" in terms of machine learning.

✓ Using the same input dataset, it compares the performance of various machine learning models. The method of evaluation places a strong focus

on how well the model predicts the final results.

✓ If the accuracy is high, the model's predictions based on the provided data will also be accurate to the fullest extent possible.
Model Evaluation Process
✓ We are aware that a crucial component of machine learning is model evaluation. The dataset is initially split into two categories: "Training
theknowledgeacademy

dataset" and "Test dataset.“

✓ Using the training dataset, we create the machine learning model and test its performance. However, we test the designed Model using a dataset

of unknown or unobserved samples of the data that are not used for training.

✓ We can determine how accurate the outcomes were by evaluating the model. If we use the training dataset to evaluate the model, it will always

show accurate predictions for the given problem for any instance of the training data; in that case, our model is not sufficiently effective to use.

✓ There are two methods for evaluating the performance of a model. Those are:
▪ Holdout
▪ Cross Validation
Model Evaluation Process
The hold out method:
theknowledgeacademy

✓ Two types of data are used for training and testing in the Holdout method, which is used to assess the performance of the model. While the

model is trained using a set of training data, its performance is measured using test data. This technique is used to evaluate how well a machine

learning model that was created using various algorithmic techniques performs on data samples that have not yet been seen. This strategy is

easy, adaptable, and quick.

Cross validation:

✓ In the cross-validation process, the entire dataset is divided into data samples, and the machine learning model is then assessed using the other

samples of data to determine the model's accuracy. In other words, we use a subset of the data to train the model and a different subset of the

data to evaluate it.


Cross Validation in ML
✓ Cross-validation is a process for validating the model efficiency by training it on the Example
theknowledgeacademy

subset of input data and testing on previously unseen subset of the input data.

✓ It is also a method for determining how well a statistical model generalises to a

different dataset.

✓ Cross-validations' fundamental steps are:

❑ Reserve a subset of the dataset as a validation set.

❑ Provide training to the model using the training dataset.

❑ Evaluate the model performance using the validation set.

❑ If the model performs well with the validation set, perform the further step,

else check for the issues.


Methods Used for Cross-Validation
✓ There are some common methods used for cross validation method.
theknowledgeacademy

Leave-P-Out Cross- K-Fold Cross-


Validation Validation

1 2 3 4 5

Validation set Leave-One-Out Cross- Stratified K-Fold Cross-


approach Validation (LOOCV) Validation
Types of Predictive Model
✓ A developed ML model is used to predict the outcomes from the provided data using predictive models. With the aid of the provided data, we
theknowledgeacademy

can forecast the results prior to receiving the model's actual output. In machine learning, prediction models are frequently used to make

educated guesses about the results of the data before designing a model.

✓ Predictive models come in various forms:

1 Classification Model

2 Clustering Model

3 Forecast Model

4 Outlier Model
Confusion Matrix
✓ N is the number of predicted classes, and NxN is a matrix structure used to measure how well a classification model performs. It is used to
theknowledgeacademy

operate on a test dataset where the true values have been determined. The matrix informs us of the number of inaccurate and accurate

predictions made by a classifier and is used to assess the model's accuracy.

✓ In order to measure Accuracy, Precision, Recall, Specificity, Sensitivity, and AUC curve, it includes values such as True Positive, False Positive, True

Negative, and False Negative. The above metrics will discuss model performance and compare it to other models to determine how effective it is.

✓ By using the mean of the True Positive and True Negative values of the entire sample values, the accuracy can be calculated. It provides

information on the total number of accurate predictions made by the model.

✓ Precision is defined as the ratio of the number of true positives to all of the positive samples that the classifier predicted to be positive. It

provides information on the positive samples that the model correctly identified.
Confusion Matrix
✓ There are four terms in confusion matrix:
theknowledgeacademy

True Positives(TP)

True Negatives(TN)

False Positives(FP)

False Negatives(FN)
theknowledgeacademy
Confusion Matrix
Confusion Matrix
✓ The following is an example to implement confusion matrix:
theknowledgeacademy
Area Under the ROC Curve (AUC-ROC)
✓ It is a common Evaluation Metric that is mostly applied to Binary Classification. The values for the True positive and False positive rates range
theknowledgeacademy

from 0 to 1. To better understand the data, a graph is created after the TPR and FPR are computed using various threshold values. The plot

between the false positive rate and the true positive rate at various values of [0,1] is what the Area Under Curve represents.

✓ In machine learning, creating an ML model alone is insufficient because we also need to assess how well it is working. It means that after creating

an ML model, we must assess and verify its quality. In these situations, we employ various Evaluation Metrics. Such an evaluation metric is the

AUC-ROC curve, which is used to show the effectiveness of a classification model. It is a well-liked and significant metric for assessing the

effectiveness of the classification model.


ROC Curve
✓ The Receiver Operating Characteristic (ROC) curve is a probability graph that displays how well a classification model performs at various
theknowledgeacademy

threshold levels.

✓ The curve is drawn between the following two parameters:

True Positive Rate or TPR

False positive Rate or FPR

TPR=TP/(TP+FN)

FPR=FP/(FP+TN)
ROC Curve
✓ The following is an example to implement ROC curve:
theknowledgeacademy
AUC Curve
✓ AUC is known as Area Under the ROC curve.
theknowledgeacademy

✓ It calculates the two-dimensional area under the entire ROC curve ranging from(0,0) to (1,1).

Example
Application of AUC-ROC Curve
theknowledgeacademy

Classification of 3D model 01

Healthcare 02

Binary Classification 03
Mean Squared Error(MSE)
✓ The amount of error in statistical models is evaluated by the mean squared error, or MSE. Between the observed and predicted values, it
theknowledgeacademy

evaluates the average squared difference. The MSE is equal to zero when a model is error-free. Its value increases as model error does as well.

✓ The mean squared error is also known as the mean squared deviation(MSD).

Where

yi is the ith observed value.

ŷi is the corresponding predicted value.

n = the number of observations.


Root Mean Squared Error(RMSE)
✓ The difference between the predicted and actual values of the provided data is known as the root mean squared error. It is the most widely used
theknowledgeacademy

metric evolution method for regression issues. It is based on the idea that errors are unbiased and has a normal distribution.

✓ The transformation between values predicted by a model and actual values is calculated using RSME (Root Mean Square Error). In other words, it

is a flaw in the methodology used to assess the accuracy and rate of any machine learning algorithm applied to a regression problem.

Σ - It represents the "sum".


di- It represents the predicted value for the ith
pi- It represents the predicted value for the ith
n - It represents the sample size.
K-fold Cross Validation
✓ Cross validation is the technique for validating the model efficiency By training it on the subset of input data and testing on previously unseen
theknowledgeacademy

subset of the input data.

✓ The stability of the model must always be tested in machine learning. This indicates that we cannot fit our model to the training dataset alone.

We dedicate a specific sample of the dataset—one that wasn't included in the training dataset—for this use. After that, before deployment, we

test our model on that sample, and the entire procedure is referred to as cross-validation. It differs from the typical train-test split in this way.
K-fold Cross Validation
✓ K-fold cross validation is the technique which divides the input dataset into K groups of samples of equal sizes.
theknowledgeacademy

✓ These samples are known as folds. For each learning sets the prediction function uses k-1 folds, and the rest of the folds are used for the test set.

✓ This approach is a very popular CV approach because it is easy to understand, and the output is less biased as compared to other methods.
theknowledgeacademy
Description

Module 3 1 Introduction to Classification

2
Classifier

3 K-Nearest Neighbours

Classification
4 How KNN works?

5 Decision Tree
theknowledgeacademy
Description

Module 3 6 Why to Use Decision Tree?

7
Decision Tree Terminologies

8 Decision Tree Steps

Classification
9 Advantages and Disadvantages (Decision Tree)

10 Logistic Regression
theknowledgeacademy
Description

Module 3 11 Logistic Function (Sigmoid Function)

12
Equation of Logistic Regression

13 Types of Logistic Regression

Classification
14 Support Vector Machine (SVM)

15 Why is it called Naive Bayes?


theknowledgeacademy
Description

Module 3 16 Bayes Theorem

17
Advantages and Disadvantages of NB classifier

18 Types of Naive Bayes Model

Classification
19 Random Forest Classification

20 Why Random Forest


theknowledgeacademy
Description

Module 3
21 Application of Random Forest Classification

22
Advantages and Disadvantages of RF
Classification
Introduction to Classification
✓ Classification is the process of finding a function which helps in dividing the dataset into class based on different parameters.
theknowledgeacademy

✓ In classification, data is divided into various classes by a computer programme that has been trained on the training dataset.
✓ The best example of classification problem is Email spam Detection.
✓ When a new email arrives, the model determines whether it is spam or not based on training data from millions of emails on various
parameters. The email is placed in the Spam folder if it is considered spam.
✓ Classification can be divided into following types:

1 Logistic Regression K-Nearest Neighbours 2

3 Support Vector machine


Naïve Bayes 4

5 Decision Tree Classification Random Forest Classification 6

7 Face recognition Detection of online frauds 8


Classification
✓ A classifier is an algorithm that implements classification on a dataset.
theknowledgeacademy

✓ Two different classifications exist:


❑ Binary Classifier: Binary classifiers are used when there are only two possible solutions to a classification problem. YES or NO, MALE or
FEMALE, SPAM or NOT SPAM, CAT or DOG, etc. are some examples.
❑ Multi-class Classifier: A classification problem is referred to as multi-class if there are more than two possible outcomes. Examples include
classifications of different types of music and different types of crops.

✓ Learners in classification problems:


✓ In classification problem there are two types of learners:
❑ Lazy Learners: Lazy Learner first stores the training dataset before waiting for the test dataset to arrive. When using a lazy learner,
classification is carried out using the training dataset's most pertinent data. Less time is spent on training, but more time is spent on
predictions.
❑ Eager Learners: Before receiving a test dataset, eager learners build a classification model using a training dataset. Eager learners spend
more time learning and less time predicting than lazy learners.
K-Nearest Neighbour(KNN)
✓ K-Nearest Neighbour is one of the simplest machine learning algorithms, based on the supervised learning method.
theknowledgeacademy

✓ The K-NN algorithm makes the assumption that the new case and the existing cases are similar, and it places the new case in the category
that is most like the existing categories.
✓ A new data point is classified using the K-NN algorithm based on similarity after all the existing data has been stored. This means that using
the K-NN algorithm, new data can be quickly and accurately classified into a suitable category.
✓ Although the K-NN algorithm is most frequently used for classification problems, it can also be used for regression.
✓ Since K-NN is a non-parametric algorithm, it makes no assumptions about the underlying data.
✓ It is also known as a lazy learner algorithm because it stores the training dataset rather than learning from it immediately. Instead, it uses the
dataset to perform an action when classifying data.
K-Nearest Neighbour(KNN)
✓ The following is an example to implement KNN:
theknowledgeacademy
How KNN works?
✓ If there are two categories, Category A and Category B, and we have a new data point, x1, which category does this data point belong in?
theknowledgeacademy

✓ We require a K-NN algorithm to address this kind of issue. K-NN makes it simple to determine the category or class of a given dataset.
Decision Tree
✓ Decision tree is a supervised learning method that can be used for both classification and regression problems, but mainly it is preferred for
theknowledgeacademy

solving Classification problems.


✓ The Decision Node and Leaf Node are the two nodes in a decision tree. Decision nodes are used to make any decision and have multiple
branches, whereas Leaf nodes shows output of those decisions and do not contain any further branches.
✓ The given dataset's features are used to perform the test or make the decisions.
✓ It is a graphical representation for gathering all feasible answers to a decision or problem based on predetermined [Link] is known as a
decision tree because, like a tree, it begins with the root node and grows on subsequent branches to form a structure resembling a tree.
Decision Tree
✓ The following is an example that demonstrates how to implement a Decision Tree classifier using the Scikit-learn library:
theknowledgeacademy
Why to Use Decision Tree?
✓ The most important thing to keep in mind when developing a machine learning model is to select the best algorithm for the dataset and
theknowledgeacademy

problem at hand.

1. 2.
Can mimic Because the
human decision tree
thinking displays a
ability while tree-like
making a structure, the
decision, so logic behind it
easy to is simple to
understand. comprehend.
Decision Tree Terminologies
✓ Root Node: The decision tree begins at the root node. The entire dataset is represented, which is then split into two or more homogeneous
theknowledgeacademy

sets.
✓ Leaf Node: After receiving a leaf node, the tree cannot be further divided; leaf nodes are the final output nodes.
✓ Splitting: In splitting, the decision node or root node is divided into sub-nodes in accordance with the specified conditions.
✓ Branch : The tree was split into two new trees.
✓ Parent Child node: The parent node of the tree and the other nodes are referred to as the child nodes.
Decision Tree Steps
✓ In a decision tree, the algorithm begins at the root node and works its way up to predict the class of the given dataset. This algorithm follows
theknowledgeacademy

the branch and jumps to the following node by comparing the values of the root attribute with those of the record (real dataset) attribute.
✓ Step 1: According to S, start the tree at the root node, which holds the entire dataset.
✓ Step 2: Utilize the Attribute Selection Measure to identify the dataset's top attribute (ASM).
✓ Step 3: Divide the S into subsets that contains possible values for the best attributes.
✓ Step 4: Create the decision tree node that contains the best attribute.
✓ Step 5: Using the subsets of the dataset generated in step 3, repeatedly create new decision trees. Continue along this path until you reach a
point where you can no longer categorise the nodes and you refer to the last node as a leaf node.
Advantages and Disadvantages(Decision Tree)
✓ Advantages
theknowledgeacademy

✓ It is easy to comprehend because it uses the same reasoning process that a human would use to arrive at any decision in the real world.
✓ For problems involving decisions, it can be very helpful.
✓ It is beneficial to consider every scenario that could result from a problem.
✓ Compared to other algorithms, less data cleaning is needed.

✓ Disadvantages
✓ The decision tree is complicated because it has many layers.
✓ The Random Forest algorithm can fix any overfitting problems it may have.
✓ The decision tree's computational complexity might rise with more class labels.
Logistic Regression
✓ One of the most well-known machine learning algorithms that falls under supervised learning techniques is logistic regression.
theknowledgeacademy

✓ It can be applied to Classification and Regression issues, but is primarily used for Classification issues.
✓ Logistic regression is mainly used to predict the categorical dependent variable with the help of independent variables.
✓ A Logistic Regression problem's output can only fall between 0 and 1.
✓ When determining the probabilities between two classes is necessary, logistic regression can be used. such as true or false, 0 or 1, whether it
will rain today, etc.
✓ Logistic regression is based on the concept of Maximum Likelihood estimation. According to this estimation, the observed data should be
most probable.
✓ Activation functions in logistic regression allow us to map values between 0 and 1 by passing the weighted sum of inputs through them. Such
an activation function is termed to as a sigmoid function, and the resulting curve is known as an S-curve or sigmoid curve.
Logistic Regression
✓ The following is an example to implement logistic regression:
theknowledgeacademy
Logistic Function(Sigmoid Function)
✓ The predicted values are converted to probabilities using a mathematical function called the sigmoid function.
theknowledgeacademy

✓ It transforms any real value between 0 and 1 into another value.


✓ The logistic regression's value must fall within the range of 0 and 1, and because it cannot go beyond this value, it takes the shape of a "S"
curve. The sigmoid function or logistic function is another name for the S-form curve.
✓ We use the threshold value concept in logistic regression, which establishes the probability of either 0 or 1. Examples include values that
tend to 1 above the threshold value and to 0 below it.
Equation of Logistic Regression
✓ The equation of logistic regression is below:
theknowledgeacademy

Advantages of Logistic Regression:


✓ Performs well when dataset is linearly separable.
✓ Although it is less likely to do so, it can still over fit in datasets with high dimensions.
✓ It is much simpler to implement, interpret, and train on.
Types of Logistic Regression
✓ Three different types of logistic regression can be distinguished based on the categories:
theknowledgeacademy

✓ Binomial:
✓ There are only two possible types of dependent variables in binomial logistic regression, such as 0 or 1, Pass or Fail, etc.

✓ Multinomial:
✓ In multinomial logistic regression, the dependent variable may be one of three or more possible unordered types, such as "cat," "dogs," or
"sheep.“

✓ Ordinal:
✓ There are three or more possible ordered types of dependent variables in ordinal logistic regression, such as "low," "Medium," or "High."
Support Vector Machine(SVM)
✓ One of the most well-liked supervised learning algorithms, Support Vector Machine, or SVM, is used to solve Classification and Regression
theknowledgeacademy

problems.
✓ However, primarily, it is used for Classification problems in Machine Learning.
✓ The SVM algorithm's objective is to establish the best line or decision boundary that can divide n-dimensional space into classes, allowing us
to quickly classify new data points in the future. A hyperplane is the name given to this optimal decision boundary.
✓ SVM selects the extreme vectors and points that aid in the creation of the hyperplane. The algorithm is referred to as a "support vector
machine" because of these extreme cases.
✓ Face detection, image classification, text categorization, etc. can all be done using the SVM algorithm.
Support Vector Machine(SVM)
✓ SVM can be of two types:
theknowledgeacademy

Non-linear
Linear SVM
SVM

The term "linearly When a dataset cannot


separable data" refers to be classified using a
data that can be divided straight line, it is said to
into two classes using only be non-linear, and the
a single straight line. Linear classification algorithm
SVM is used to classify such used is known as a non-
data, and the classifier linear SVM classifier.
used is known as the Linear
SVM classifier.
Why it is called Naive Bayes?
Naive Bayes
theknowledgeacademy

✓ The Nave Bayes algorithm is a supervised learning method for classification problems that is based on the Bayes theorem.
✓ It is mainly used in text classification that includes a high-dimensional training dataset.
✓ Naïve Bayes Classifier is one of the simple and most effective Classification algorithms which helps in building the fast machine learning
models that able to make quick predictions.
✓ Being a probabilistic classifier, it makes predictions based on the probability that an object will occur.
✓ Spam filtration, Sentimental analysis, and article classification are a few examples of Naive Bayes algorithms that are frequently used.
Why it is called Naive Bayes?
✓ The following is an example implement naive bayes classification using the scikit-learn library:
theknowledgeacademy
Why it is called Naive Bayes?
✓ The words Naive and Bayes, which make up the Nave Bayes algorithm, are as follows:
theknowledgeacademy

✓ Naive:
✓ Because it presumes that the occurrence of one feature is unrelated to the occurrence of other features, it is known as naive.
✓ A red, spherical, sweet fruit, for instance, is recognised as an apple if the fruit is identified based on its colour, shape, and flavour. So,
without relying on one another, each characteristic helps to identify it as an apple.

✓ Bayes:
✓ As a result of its reliance on the Bayes' Theorem principle, it is known as Bayes.
Bayes Theorem
✓ The Bayes theorem, also referred to as Bayes' Rule or Bayes' law, is used to calculate the likelihood of a hypothesis given some prior
theknowledgeacademy

information. It depends on the conditional probability.


✓ The Bayes theorem's formula is as follows:

✓ Where, p(A|B) is Posterior probability means Probability of hypothesis A on the observed event B.
✓ p(A|B) is Likelihood probability means Probability of the evidence given that the probability of a hypothesis is true.
✓ P(A) is Prior Probability means Probability of hypothesis before observing the evidence.
✓ P(B) is Marginal Probability means Probability of Evidence.
Advantages and Disadvantages of NB classifier
✓ Advantages:
theknowledgeacademy

✓ One of the quick and simple machine learning algorithms to predict a class of datasets is naive Bayes.
✓ Both binary and multi-class classifications can be done using it.
✓ In comparison to other algorithms, it performs well in multi-class predictions.
✓ It is the most frequently used solution for text classification issues.

✓ Disadvantages:
✓ Naive Bayes cannot discover the relationship between features because it presumes that all features are either independent or unrelated.
Types of Naive Bayes Model
✓ There are three different kinds of naive Bayes models, and they are as follows:
theknowledgeacademy

✓ Gaussian:
✓ The Gaussian model presupposes that features are distributed normally. This indicates that the model assumes that predictor values are
samples from the Gaussian distribution if they take continuous values rather than discrete ones.

✓ Multinomial:
✓ When the data is multinomially distributed, the Multinomial Naive Bayes classifier is employed. It indicates which category a specific
document falls under, such as Sports, Politics, Education, etc., and is primarily used to solve document classification issues. Word frequency
is used by the classifier as a predictor.

✓ Bernoulli:
✓ Similar to the Multinomial classifier, the Bernoulli classifier uses independent Boolean variables as predictor variables. such as determining
whether a word is used or not in a document. For tasks involving document classification, this model is renowned.
Random Forest Classification
✓ Popular machine learning algorithm Random Forest is a part of the supervised learning methodology. It can be applied to ML problems
theknowledgeacademy

involving both classification and regression.


✓ It is based on the idea of ensemble learning, which is a method of combining various classifiers to address complex issues and enhance
model performance.
✓ According to what its name implies, "Random Forest is a classifier that contains a number of decision trees on different subsets of the given
dataset and takes the average to enhance the predictive accuracy of that dataset.
✓ Instead of relying on a single decision tree, the random forest uses predictions from each tree and predicts the result based on the votes of
the majority of predictions.
✓ The greater number of trees in the forest leads to higher accuracy.
Random Forest Classification
✓ The following is an example to implement random forest classification:
theknowledgeacademy
Why Random Forest
✓ In comparison to other algorithms, it requires less training time.
theknowledgeacademy

✓ Even for the large dataset, it runs effectively and predicts the outcome with a high degree of accuracy.
✓ When a significant amount of the data is missing, accuracy can still be maintained.

✓ The working process can be described in below steps:


❑ Step1: Pick K data points at random from the training set.
❑ Step2: Create the decision trees linked to the chosen data points (Subsets).
❑ Step3: For any decision trees you intend to construct, select N.
❑ Step4: Repeat step 1 and 2.
❑ Step5: Find each decision tree's predictions for any new data points, then place them in the category that receives the most votes.
Application of Random Forest Classification
Random forest is primarily used in four sectors:
theknowledgeacademy

✓ Banking: Banking sector mostly uses this algorithm for the identification of loan risk.
✓ Medicine: With the help of this algorithm, disease trends and risks of the disease can be identified.
✓ Land Use: We can identify the areas of similar land use by this algorithm.
✓ Marketing: Marketing trends can be identified using this algorithm.
Advantages and Disadvantages of RF
Advantages
theknowledgeacademy

✓ Both classification and regression tasks can be handled by Random Forest.


✓ It is able to handle big datasets with lots of dimensions.
✓ It improves the model's accuracy and avoids the overfitting problem.

Disadvantages
✓ Random forest can be used for both classification and regression tasks, but regression tasks are not better suited for it.
theknowledgeacademy
Description

Module 4 1 Introduction to Unsupervised Learning

2 Types of Unsupervised Algorithm

3 Advantages and Disadvantages of UL

Unsupervised learning
4 Unsupervised Learning Algorithms

5 Steps for K-means Clustering

6 Elbow Method

PRINCE2® V2.2.9
theknowledgeacademy
Description

Module 4 7 Hierarchical Clustering

8 Why Hierarchical Clustering

9 Density Based Clustering (DBSCAN)


Unsupervised learning

10 Apriori Algorithm

11 Components of Apriori Algorithm

PRINCE2® V2.2.9
Introduction to Unsupervised Learning
✓ Models are not supervised using training datasets when using the machine learning technique known as unsupervised learning. Instead,
theknowledgeacademy

models themselves read and understand the provided data to reveal hidden patterns and insights.
✓ It is comparable to the learning process that occurs in the human brain when learning something new.
✓ Unsupervised learning is a subcategory of machine learning in which models are trained using unlabeled datasets and are free to act on the
data without being checked by a human observer.
✓ Finding the underlying structure of a dataset, classifying the data into groups based on similarities, and representing the dataset in a
compressed format are the objectives of unsupervised learning.
Types of Unsupervised Algorithm
✓ The unsupervised algorithm is divided into two parts.
theknowledgeacademy

✓ Clustering
❑ Clustering is a technique for organising objects into clusters so that the objects that share the most similarities stay in one group and share
little to none with the objects in another group. The commonalities between the data objects are discovered through cluster analysis, and
they are then categorised according to whether or not they exist.

✓ Association
❑ An unsupervised learning technique called an association rule is used to uncover the connections among the variables in a sizable database.
It establishes the group of items that co-occur in the dataset. Marketing strategy is more effective thanks to the association rule. People who
buy X (let's say, bread) also frequently buy Y (let's say, butter or jam). Market Basket Analysis is an illustration of an association rule in action.
Advantages and Disadvantages of UL
Advantages
theknowledgeacademy

✓ Compared to supervised learning, unsupervised learning is used for tasks that are more complex because it lacks labelled input data.
✓ Unsupervised learning is preferred because unlabeled data is simpler to obtain than labelled data.

Disadvantages:
✓ Due to the lack of a corresponding output, unsupervised learning is inherently more challenging than supervised learning.
✓ As the input data is not labelled and the algorithms do not know the precise output in advance, the outcome of the unsupervised learning
algorithm may be less accurate.
Unsupervised Learning Algorithms
✓ Popular unsupervised learning algorithms are listed below:
theknowledgeacademy

1 K-means clustering Principal component analysis 2

3 KNN(k-nearest neighbors) Independent component analysis 4

5 Hierarchal clustering Apriori algorithm 6

7 Neural Networks Singular value decomposition 8


Steps for K-means Clustering
K-means Clustering
theknowledgeacademy

✓ K-means clustering is an unsupervised learning algorithm that is used to solve the clustering problem in machine learning or data science.
✓ K-means grouped the unlabeled dataset into different clusters. Here, K specifies how many pre-defined clusters must be created as part of
the process; for example, if K=2, there will be two clusters, if K=3, there will be three clusters, and so on.
✓ Each cluster has a centroid assigned to it because the algorithm is centroid-based. This algorithm's primary goal is to reduce the total
distances between each data point and its corresponding clusters.
✓ The algorithm starts with an unlabeled dataset as its input, divides it into k clusters, and then repeats the process until it runs out of clusters
to use. In this algorithm, the value of k should be predetermined.
Steps for K-means Clustering
✓ The following is an example to implement K-means clustering:
theknowledgeacademy
Steps for K-means Clustering
✓ The following steps explain how the K-Means algorithm functions:
theknowledgeacademy

✓ Step 1: To determine the number of clusters, choose K.


✓ Step 2: Pick K centroids or random points. (It might not be the input dataset.)
✓ Step 3: Assign each data point to its nearest centroid, which will create the K clusters that have been predetermined.
✓ Step 4:Place a new centroid for each cluster after computing the variance.
✓ Step 5:Re-assign each data point to the new centroid of each cluster by repeating the third step.
✓ Step 6:If there is a reassignment, proceed to step 4; otherwise, proceed to finish.
✓ Step 7:The model is complete
Elbow Method
✓ One of the most widely used techniques for determining the ideal number of clusters is the Elbow method. The WCSS value concept is used
theknowledgeacademy

in this technique. The term "total variations within a cluster" is modified as "WCSS," which stands for Within Cluster Sum of Squares.

WCSS= ∑Pi in Cluster1 distance(Pi C1)2 +∑Pi in Cluster2distance(Pi C2)2+∑Pi in CLuster3 distance(Pi C3)2
Hierarchical Clustering
✓ Another unsupervised machine learning algorithm, hierarchical clustering (also known as
theknowledgeacademy

hierarchical cluster analysis, or HCA), is used to cluster unlabeled datasets.


✓ With this algorithm, we create a tree-like structure known as a dendrogram that represents the
hierarchy of clusters.
✓ K-means clustering and hierarchical clustering can produce results that occasionally resemble one
another, but they actually function differently. As we did with the K-Means algorithm, there is no
requirement to predetermine the number of clusters.
✓ There are two methods for using the hierarchical clustering technique:
1. Agglomerative: Agglomerative is a bottom-up approach in which the algorithm begins by treating
each data point as a separate cluster and then merges those clusters until only one is left.
2. Divisive: Because it takes a top-down approach, the dividing algorithm is the opposite of the
agglomerative algorithm.
Hierarchical Clustering
✓ The following is an example of using scikit-learn agglomerative clustering to perform hierarchical clustering:
theknowledgeacademy
Why Hierarchical Clustering
✓ K-means clustering has shown that this algorithm has some drawbacks, including a predetermined number of clusters and a tendency to
theknowledgeacademy

always try to create clusters of the same size.


✓ Because we don't need to be aware of the predefined number of clusters when using the hierarchical clustering algorithm, we can choose
this algorithm to address these two problems.
Density Based Clustering(DBSCAN)
✓ Density-Based Spatial Clustering of Applications with Noise is known as DBSCAN.
theknowledgeacademy

✓ A well-liked density-based data clustering algorithm is DBSCAN. This algorithm separates the high-density regions from the low-density
regions of the data before clustering the data points.
✓ The advantage of this algorithm over the K-Means algorithm is that we don't need to supply the number of clusters needed beforehand.
✓ The robustness to outliers of DBSCAN clustering is its most interesting characteristic.
Density Based Clustering(DBSCAN)
✓ The following is an example to implement DBSCAN:
theknowledgeacademy
Density based clustering(DBSCAN)
✓ Epsilon and minPoints are the only two parameters needed by DBSCAN. MinPoints is the bare minimum number of data points necessary
theknowledgeacademy

inside that circle for that data point to be classified as a Core point, and Epsilon is the radius of the circle to be created around each data
point to check the density.
✓ In higher dimensions, the circle becomes a hypersphere with a radius of epsilon, and the minimum number of data points needed inside the
hypersphere is minPoints.
✓ Every data point is encircled by an epsilon radius circle in DBSCAN before being divided into three categories: Core point, Border point, and
Noise. If there are at least "minPoints" number of points in the circle surrounding a data point, it qualifies as a core point.
✓ If the number of points is less than minPoints, then it will be classified as Border Point, and if there are no other data points around any data
point within epsilon radius, then it treated as Noise.
Apriori Algorithm
✓ The Apriori algorithm is made to operate on databases that contain transactions and generate association rules using frequent itemsets. It
theknowledgeacademy

establishes how strongly or weakly two objects are connected using these association rules.
✓ This algorithm calculates the itemset associations quickly by using a breadth-first search and a hash tree. Finding the frequent item sets from
a large dataset involves an iterative process.
✓ In the year 1994, R. Agrawal and Srikant presented this algorithm. It assists in identifying products that can be purchased in combination and
is primarily used for market basket analysis. It can also be applied to the healthcare industry to identify patient drug reactions.
✓ Itemsets that are frequently used are those whose support is higher than the threshold value or the minimum support specified by the user.
This means that if A and B together are the frequent itemsets, then A and B should also be the frequent itemset individually.
✓ Assume that the two transactions are A={1,2,3,4,5} and B={2,3,7}. In these two transactions, the frequent item sets are 2 and 3.
Components of Apriori Algorithm
✓ The Apriori algorithm has three main components as listed below:
theknowledgeacademy

✓ Support:
✓ Support is the term used to describe a product's inherent popularity. When you divide the total number of transactions by the number of
transactions that make up that product, you get the support.
✓ Confidence:
✓ Confidence refers to the likelihood that customers will purchase various products at once.
✓ Lift:
✓ Lift refers to the increase in the proportion of product A purchases made when product B are purchased.
theknowledgeacademy
Description

Module 5 1 Dimensionality Reduction

2 Need of Dimensionality Reduction

3 Types of Dimensionality Reduction


Dimensionality
Reduction
4 Principal Component Analysis (PCA)

5 Steps for PCA Algorithm

PRINCE2® V2.2.9
theknowledgeacademy
Description

Module 5 6 What is Variance?

7 What is Covariance?

8 What is Correlation?
Dimensionality
Reduction
9 Application of PCA

10 What is P-Value?

PRINCE2® V2.2.9
theknowledgeacademy
Description

Module 5 11 Hypothesis Testing

12 Hypothesis in Statistics

13 Critical Values
Dimensionality
Reduction
14 Z Test

15 Chi-Square Test

PRINCE2® V2.2.9
theknowledgeacademy
Description

Module 5 16 ANOVA

17 Normal Distribution

18 Statistical Significance
Dimensionality
Reduction
19 Errors in P-value

20 Linear Discriminant Analysis (LDA)

PRINCE2® V2.2.9
theknowledgeacademy
Description

Module 5 21 Working of Linear Discriminant Analysis

22 How to Prepare Data for LDA

23 Real World Application of LDA


Dimensionality
Reduction
24 Difference Between PCA and LDA

25 Overfitting and Underfitting in ML

26 How to Avoid the Overfitting in the Model

PRINCE2® V2.2.9
Dimensionality Reduction
✓ There are frequently too many factors on which to base the final classification in machine learning classification problems. These variables are
theknowledgeacademy

referred to as features.
✓ The more features there are, the more difficult it is to visualise the training set and then work on it. Most of these characteristics are
sometimes correlated and thus redundant.
✓ Dimensionality reduction algorithms come into play here. The process of reducing the number of random variables under consideration by
obtaining a set of principal variables is known as dimensionality reduction.
✓ It is divided into two parts: feature selection and feature extraction.
Dimensionality Reduction
Components of Dimensionality Reduction
theknowledgeacademy

✓ Feature selection: In this step, we attempt to find a subset of the original set of variables, or features, in order to obtain a smaller subset
that can be used to model the problem. It is usually accomplished in three ways:
✓ Filter
✓ Wrapper
✓ Embedded
✓ Feature extraction: This method reduces data from a high-dimensional space to a lower-dimensional space, i.e. a space with fewer
dimensions..
Need of Dimensionality Reduction
The following are some of the advantages of using dimensionality reduction on a dataset:
theknowledgeacademy

✓ As the number of dimensions decreases, so does the amount of space required to store the data.
✓ Fewer dimensions result in less computation/training time.
✓ Some algorithms do not perform well when the dimensions are large. So, in order for the algorithm to be useful, these dimensions must be
reduced.
✓ It handles multicollinearity by eliminating redundant features.
✓ It aids in the visualization of data.
Types of Dimensionality Reduction
✓ Dimensionality reduction can be achieved through multiple methods. Some of the methods are as follows:
theknowledgeacademy

✓ PCA(Principal Component Analysis)


✓ LDA(Linear Discriminant Analysis)
Principal Component Analysis(PCA)
✓ An unsupervised learning algorithm called principal component analysis is used in machine learning to reduce dimensionality. With the aid of
theknowledgeacademy

orthogonal transformation, it is a statistical process that transforms the observations of correlated features into a set of linearly uncorrelated
features.
✓ The Principal Components are these newly altered features. One of the widely used tools for exploratory data analysis and predictive
modelling is this one. It is a method for identifying significant patterns in the provided dataset by lowering the variances.
✓ Typically, PCA looks for the surface with the lowest dimensionality onto which to project the high-dimensional data.
✓ PCA functions by taking into account each attribute's variance because a high attribute demonstrates a good split between classes, which
lowers the dimensionality.
✓ Image processing, movie recommendation systems, and power allocation optimization in various communication channels are some
examples of PCA's practical applications.
✓ Since it uses a feature extraction technique, it keeps the crucial variables and discards the unimportant ones.
Principal Component Analysis(PCA)
✓ The PCA algorithm is based on some mathematical ideas such as:
Variance and Covariance
theknowledgeacademy

Eigenvalues and Eigen factors

✓ Some terms used in PCA algorithm are:


✓ Dimensionality: Dimensionality is the quantity of features or variables that the dataset contains.
✓ Correlation: It denotes how closely two variables are correlated with one another. For instance, if one variable changes, the other variable
also changes. The correlation score lies between -1 and +1. Here, -1 denotes an inverse relationship between the variables, and +1 denotes a
direct relationship between the variables.
✓ Orthogonal: It states that variables are not correlated with one another, so there is no correlation between the two.
✓ Eigenvectors: if a non-zero vector v and a square matrix M are both provided. In the event that Av is v's scalar multiple, v will then be an
eigenvector.
✓ Covariance Matrix : The Covariance Matrix is a matrix that represents the covariance between the two variables.
Steps for PCA algorithm
✓ Below are the steps for PCA algorithm:
theknowledgeacademy

Getting the data set

Repressing the data into a structure

Standardizing the data

Calculating the covariance of Z

Calculating the Eigen vector and Eigen value

Sorting the Eigen vector

Calculating the new features of principal components

Remove less features from the new dataset


What is Variance?
✓ Variance in statistics measures how spread out a set of data points is around the mean. In other words, it quantifies the extent to which each
theknowledgeacademy

number in the dataset differs from the mean and thus from every other number in the set.

✓ You can calculate the variance using the var() function from the numpy library, which is highly efficient for numerical operations on large
datasets. Below is a simple code example to demonstrate how to calculate the variance of a list of numbers:
What is Covariance?
✓ Covariance is a scale-dependent measure of the relationship between two variables, i.e., how much one variable will change when the other
theknowledgeacademy

variable changes.
✓ The equation of covariance is given below:

✓ Where:
What is Covariance?
✓ The following is an example using NumPy to calculate the covariance between two arrays:
theknowledgeacademy
What is Correlation?
✓ Correlation is a statistical measure that describes the extent to which two variables are related. It quantifies the degree to which a change in
one variable is associated with a change in another variable. The correlation coefficient can range from -1 to 1, where:
theknowledgeacademy

1. 1 indicates a perfect positive correlation: as one variable increases, the other variable also increases.

2. -1 indicates a perfect negative correlation: as one variable increases, the other variable decreases.

3. 0 indicates no correlation: there is no linear relationship between the variables.

Example
Application of PCA
✓ Principal Component Analysis (PCA) is a statistical technique used for dimensionality reduction while preserving as much of the variability in
theknowledgeacademy

the data as possible. It is commonly used in various fields to simplify complex datasets, improve visualizations, enhance algorithm
performance, or identify underlying variables influencing the data. The following are the various applications of PCA:

01 02 Feature
03 Noise
Data
Visualization Reduction Reduction

04 Exploratory 05 Pattern
Data Analysis Recognition
What is P-Value
✓ The P-value, also known as probability value, is used in statistical hypothesis testing to observe test results or more extreme results under
theknowledgeacademy

the presumption that the null hypothesis (H0) is true.


✓ The p-value is one of many concepts used in data science that have been adapted from other fields.
✓ The statistical concept of p-value is used extensively in machine learning and data science.
✓ The smallest level of significance at which the null hypothesis is least or rejected is provided by the P-value, which is also used as an
alternative to determine the point of rejection.
What is P-Value
✓ The level of significance () is defined as a p-value of 0.05. Typically, it is thought of using the following two suggestions:
theknowledgeacademy

❑ If the p-value is greater than 0.05, the null hypothesis must be accepted because of the high p-value.
❑ If the p-value is less than 0.05, the null hypothesis must be accepted and the result is deemed statistically significant.
✓ Our primary objective in statistics is to assess the statistical significance of a result, and we base this assessment on the following three
ideas:
❑ Normal Distribution
❑ Hypothesis Testing
❑ Statistical Significance
What is P-Value
✓ The following example to calculate p-value:
theknowledgeacademy
Hypothesis Testing
✓ In projects involving machine learning and data science, the term hypothesis is frequently used.
theknowledgeacademy

✓ We all know that one of the most potent technologies in use today, machine learning, enables us to predict outcomes based on prior data.
✓ Additionally, experts in data science and machine learning run experiments with the goal of resolving a problem. These ML experts and data
scientists make a preliminary assumption regarding the problem's resolution.
✓ In machine learning, this presumption is referred to as a hypothesis. The terms hypothesis and model are frequently used interchangeably in
machine learning.
✓ A model, on the other hand, is a mathematical representation that is used to test the hypothesis, whereas a hypothesis is an assumption
made by scientists.
Hypothesis Testing
✓ Procedures for Testing Hypotheses
theknowledgeacademy

❑ Claim a Null hypothesis for the experiment.


❑ Describe the alternate hypothesis, which is opposite to the null hypothesis.
❑ Decide on the alpha value that will be used in the experiment.
❑ Utilize the normal distribution to calculate the z-score.
❑ In order to verify the statistical significance, compare the P-value.
Hypothesis Testing
✓ The following is an example of a hypothesis test for the mean, using python's SciPy library:
theknowledgeacademy
Hypothesis in Statistics
✓ It is also regarded as an assumption of the output, much like the hypothesis in machine learning. But since it can be disproven in the
theknowledgeacademy

presence of enough evidence, it is falsifiable.


✓ Statisticians cannot accept any hypothesis because it is merely an illusory result based on probability, in contrast to machine learning.
✓ We need to be aware of the following two key categories of hypotheses:

✓ Null Hypothesis:
✓ A statistical hypothesis known as a null hypothesis states that no statistically significant effect is present in the given set of observations.
✓ It is also referred to as conjecture, and it is used in quantitative analysis to determine whether or not theories about markets, investments,
and finance are true or false.

✓ Alternate hypothesis:
✓ If either of the two hypotheses is true, the other must be false because an alternative hypothesis is a direct contradiction of the null
hypothesis.
✓ To put it another way, an alternative hypothesis is a type of statistical hypothesis that asserts the existence of a significant effect in the given
set of observations.
Critical Values
✓ A p-value is often returned by statistical hypothesis tests, and it is used to interpret the results of
the test.
theknowledgeacademy

✓ When a p-value is not returned by a test, a different approach must be taken in order to directly
interpret the calculated test statistic.

✓ Critical values from the distribution of the test statistic can be used to interpret a statistic
produced by a statistical hypothesis test.

✓ The following are some examples of statistical hypothesis tests and the distributions from which
critical values can be determined:

➢ Gaussian distribution: Z-Test.

➢ Chi-Squared distribution: Chi-Squared test.

➢ F-distribution :ANOVA.
Z Test
✓ When the population standard deviation is known and the sample size is greater than or equal to 30, a z test is performed on a normal
theknowledgeacademy

distribution.
✓ Calculating the z critical value is as follows:
✓ Find the alpha level.
✓ To compute the alpha level for a two-tailed test, subtract from 1.
✓ The alpha level is subtracted from 0.5 for a one-tailed test.
✓ To find the z critical value, look up the area in the z distribution table.
✓ A negative sign must be added to the critical value at the conclusion of the calculation for a left-tailed test.
theknowledgeacademy
Z Test
Example Code
Chi-Square Test
✓ To see if the sample data and population data agree, use the chi-square test. It can also be used to assess the relationship between two
theknowledgeacademy

variables by comparing them.


✓ The following is the chi-square critical value:
✓ Determine the level of alpha.
✓ The degrees of freedom are calculated by deducting 1 from the sample size (df).
✓ The chi-square critical value is obtained using the chi-square distribution table by intersecting the row of the df and the column of the alpha
value.
Chi-Square Test
Example Code
theknowledgeacademy
ANOVA
✓ Analysis of Variance, or ANOVA, was created by Ronald Fisher.
theknowledgeacademy

✓ You can find out if there are any statistical differences between the means of three or more independent groups using one-way analysis of
variance.
✓ With the null hypothesis that the means of the various groups are equal, you would use ANOVA to understand how the various groups
respond.
✓ A statistically significant result indicates that there is inequity between the two populations.
✓ The sample cases must be distinct from one another.
✓ The group's variance must be roughly equal.
theknowledgeacademy

Example
ANOVA
Normal Distribution
✓ The probability distribution function is the normal distribution, also referred to as the Gaussian distribution. It is symmetric around the
theknowledgeacademy

mean, and a graph plot can be used to visualise the distribution of data.
✓ It resembles a bell-shaped curve and demonstrates that data close to the mean are more likely to occur than data far from the mean.
✓ The mean and standard deviation are the two key concepts in a normal distribution. The mean and standard deviation for a normal
distribution are 0 and 1, respectively.
✓ Z-score calculation is necessary for hypothesis testing. The Z-score is the number of standard deviations a data point has from its mean.
Normal Distribution
Example
theknowledgeacademy
Statistical Significance
✓ Calculating the p-value has the purpose of identifying the statistical significance of the hypothesis test.
theknowledgeacademy

✓ We must first set a threshold, known as alpha, in order to accomplish this. Before conducting an experiment, the value of alpha should
always be set to either 0.05 or 0.01.
✓ If the observed p-value is less than alpha, the result is considered significant.

Example
Errors in P-value
✓ There are two types of errors are defined for P-value
theknowledgeacademy

❑ Type I error
❑ Type II error

✓ Type I error: It is known as the incorrect or false rejection of the Null hypothesis. The incorrect or erroneous rejection of the null hypothesis
is what it is known as. The maximum probability of this error is alpha, and it is predetermined. The dataset's sample size has no bearing on
the error. As we increase the number of tests or endpoints, the type I error rises.

✓ Type II error: The incorrect acceptance of the null hypothesis is referred to as a type II error. The sample size and alpha value affect beta,
which measures the likelihood of a type II error. The true population effect cannot be used to calculate the beta. As sample size increases,
beta value decreases because it is inversely proportional to sample size.
Linear Discriminant Analysis(LDA)
✓ LDA is one of the frequently employed dimensionality reduction methods in machine learning to address problems involving more than two
theknowledgeacademy

classes.
✓ It is also referred to as Discriminant Function Analysis (DFA) or Normal Discriminant Analysis (NDA) .
✓ LDA is one of the most popular dimensionality reduction methods for supervised classification issues in machine learning.
✓ It is also regarded as a pre-processing stage for applications of pattern classification and modelling variations in ML.
✓ The Linear Discriminant Analysis model is regarded as the most popular method to solve such classification problems whenever it is
necessary to efficiently separate two or more classes with multiple features. For instance, suppose we need to effectively separate two
classes that each have a number of features. When we categorise them using just one feature, it might result in overlap.
Linear Discriminant Analysis(LDA)
✓ The following is an example to implement LDA:
theknowledgeacademy
Working of Linear Discriminant Analysis
✓ LDA is used as a dimensional reduction technique in machine learning, using which we can easily transform a 2-D and 3-D graph inti a 1-
theknowledgeacademy

dimensional plane.
✓ It can maximize the distance between means of two classes.
✓ It minimize the variance within the individual class.
How to Prepare Data for LDA
✓ The following are some recommendations that should always be taken into account when gathering data to create an LDA model:
theknowledgeacademy

✓ Classification Problem: LDA is primarily used to classify the output variable's categorical nature in classification problems. It is appropriate
for problems involving binary and multiple classes in classification.
✓ Gaussian Distribution: The Gaussian Distribution of the input variables is applied by the standard LDA model. One should review the
univariate distribution of each attribute and transform them into more Gaussian-looking distributions.
✓ Remove outliers: It is a good idea to start by removing any outliers from your data because they can skew the fundamental statistics, like the
mean and standard deviation, that are used in LDA to distinguish between classes.
✓ Same variance: It is always preferable to first standardise the data before implementing an LDA model because LDA always assumes that all
the input variables have the same variance. As a result, the Mean will be 0 and the standard deviation will be 1.
Real World Application of LDA
✓ The below are the real world applications of LDA :
theknowledgeacademy

Face reorganisation

Medical

Customer Identification

In Learning
Difference Between PCA and LDA
✓ PCA is an unsupervised algorithm that only seeks to identify the principal components in order to maximise the variance in the given dataset.
✓ It is unconcerned with classes or labels. LDA, a supervised algorithm, also seeks to identify the linear discriminants to represent the axes that
theknowledgeacademy

maximise separation between various classes of data.


✓ Compared to PCA, LDA is much better suited to multi-class classification tasks. The assumption is that PCA will perform well despite the relatively
small sample size.
✓ As dimensionality reduction methods, LDA and PCA are both employed, with PCA coming first and LDA coming after.
Overfitting and Underfitting in ML
✓ The two main issues that affect machine learning and lower the performance of the machine learning models are overfitting and underfitting.
✓ Each machine learning model's primary objective is to generalise effectively. The ability of an ML model to adapt the provided set of unknown input
theknowledgeacademy

to produce a suitable output is defined here as generalisation.


✓ It indicates that it can generate trustworthy and accurate output after receiving training on the dataset. As a result, underfitting and overfitting are
the two terms that need to be examined in order to determine how well the model performs and generalises.
✓ Below are some fundamental terms that will aid in a thorough understanding of overfitting and underfitting:
❑ Signal: The true underlying pattern of the data that enables the machine learning model to learn from the data is referred to as the signal.
❑ Noise: Noise is unneeded and irrelevant data that degrades the model's performance.
❑ Bias: When machine learning algorithms are oversimplified, a prediction error known as bias is introduced into the model. Alternately, it could be the
discrepancy between the expected and actual values.
❑ Variance: This is what happens when a machine learning model performs well with the training dataset but poorly with the test dataset.
Overfitting and Underfitting in ML
Overfitting
theknowledgeacademy

✓ When our machine learning model tries to include all the data points—or more—that are present in the dataset, this is known as overfitting.
✓ As a result, the model begins to cache inaccurate values and noise from the dataset, which lowers the model's efficiency and accuracy. High variance
and low bias characterise the overfitted [Link] more training we give our model, the more likely overfitting is to occur.
✓ Below is an example of using Python's scikit-learn library where we deliberately cause a decision tree to overfit and then compare its accuracy on
training and test sets:
Overfitting and Underfitting in ML
Underfitting
theknowledgeacademy

✓ When our machine learning model is unable to recognise the data's underlying trend, underfitting occurs.
✓ The feeding of training data can be stopped early to prevent overfitting in the model, but this may prevent the model from learning enough from the
training data. As a result, it might be unable to identify the dominant trend in the data's best fit.
✓ Underfitting occurs when a model cannot learn enough from the training data, which lowers accuracy and results in unreliable predictions. High bias
and low variance characterise an underfitted model.
✓ The following is an example to demonstrate underfitting with linear regression:
How to Avoid the Overfitting in the Model
✓ The performance of the machine learning model is deteriorated by both overfitting and underfitting. However, overfitting is the primary culprit, so
there are a few ways we can lessen its occurrence in our model.
theknowledgeacademy

➢ Cross-validation
➢ Training with more data
➢ Removing features
➢ Early stopping the training
➢ Regularization
How to Avoid the Underfitting in the Model
✓ The performance of the machine learning model is deteriorated by both overfitting and underfitting.
✓ There are a few ways we can lessen its occurrence in our model.
theknowledgeacademy

❑ By lengthening the model's training period.


❑ By expanding the selection of features.
theknowledgeacademy
Description

Module 6 1 Introduction to Deep Learning

2 Importance of Deep Learning

3 Neural Network Architecture

Deep Learning
4 Neural Network Components

5 Neural Network Algorithms

PRINCE2® V2.2.9
theknowledgeacademy
Description

Module 6 6 Convolutional Neural Networks (CNNs)

7 Long Short Memory Network (LSTMs)

8 Recurrent Neural Networks (RNNs)

Deep Learning
9 Generative Adversarial Networks (GANs)

10 Radial Basis Function Networks (RBFN)

PRINCE2® V2.2.9
theknowledgeacademy
Description

Module 6 11 Multilayer Perceptron's (MLPs)

12 Self-Organising Maps (SOMs)

13 Deep Belief Networks (DBNs)

Deep Learning
14 Restricted Boltzmann Machine (RBMs)

15 Artificial Neural Networks (ANNs)

PRINCE2® V2.2.9
theknowledgeacademy
Description

Module 6 16 Feed Forward Neural Network

17 Autoencoders

18 MNIST

Deep Learning
19 Deep Learning Applications

PRINCE2® V2.2.9
Introduction to Deep Learning
✓ Deep Learning is a subset of machine learning that utilizes neural networks with multiple layers (hence "deep") to analyze various levels of
theknowledgeacademy

abstract data.
✓ These architectures mimic the human brain in processing data through artificial neurons, enabling models to make sense of complex and large
datasets.
✓ Deep Learning has gained immense popularity due to its ability to achieve impressive accuracy in tasks such as image recognition, natural
language processing, and speech recognition.
✓ The strength of deep learning lies in its ability to perform feature extraction automatically, learning intricate patterns in data without manual
intervention.
✓ This capability is powered by large amounts of labeled data and high computational power, often utilizing GPUs for efficient training.
✓ Models like convolutional neural networks (CNNs) and recurrent neural networks (RNNs) are commonly used, each suited for different types of
data and applications.
✓ As technology evolves, deep learning continues to push the boundaries of what's possible in AI, making significant impacts across industries
including healthcare, automotive, entertainment, and finance.
Importance of Deep Learning
✓ Deep Learning has revolutionized the field of artificial intelligence by enabling machines to solve complex problems that were once considered
beyond their capabilities. This advanced form of machine learning has become crucial for interpreting large and complex datasets accurately.
theknowledgeacademy

✓ The following are the key importance of deep learning:

➢ Automated Feature Extraction: Deep learning automates the extraction of features from raw data, reducing the need for manual feature
engineering and allowing models to learn more effective representations.

➢ Handling Unstructured Data: It excels in handling unstructured data such as images, audio, and text, making it invaluable in fields like computer
vision and natural language processing.

➢ Improved Accuracy: As deep learning models are exposed to more data, they tend to improve their accuracy and efficiency, often outperforming
other machine learning techniques.

➢ Real-Time Decision Making: Deep learning models can process and analyze data in real-time, which is crucial for applications requiring
immediate responses, such as autonomous driving.

➢ Scalability: These models scale well with data and complexity, enabling them to tackle problems of larger magnitude and higher complexity as
more computational power becomes available.

➢ Personalization: Deep learning powers personalized experiences in various services, from content recommendations in streaming services to
personalized shopping experiences online.
Neural Network Architecture
✓ Artificial neurons are used to create complex structures called neural networks, which can process multiple inputs and produce a single output.
theknowledgeacademy

✓ A Neural Network's main function is to convert input into actionable output. A neural network typically has an input layer, an output layer, and
one or more hidden layers.
✓ All of the neurons in a neural network interact with one another, making them all connected.
✓ Every aspect of the dataset at hand, as well as any potential relationships between the various data parts, can be recognised and observed by
the network.
✓ Neural networks are able to identify extremely complex patterns in huge amounts of data in this way.
Neural Network Components
✓ Neural network consists of three main component.
theknowledgeacademy

❑ Input layer
❑ Hidden layer
❑ Output layer
Neural Network Components
✓ Input layer:
theknowledgeacademy

➢ The neural network's top layer is this one. It receives input signals or values and sends them to the following layer. The input signals (values) are
not subjected to any operations, and no weights or biases are assigned.
✓ Hidden layer:
➢ Between the input and output layers of a synthetic neural network is a layer known as the hidden layer, wherein artificial neurons process a set
of weighted inputs to generate an output using an activation function.
➢ It is a common component of almost every neural network in which engineers simulate the different types of activity that take place in the
human brain.
✓ Output layer:
➢ The final layer of neurons in an artificial neural network that generates predetermined outputs for the programme is known as the output layer.
Given that output layer neurons are the final "actor" nodes on the network, they may be constructed or observed differently even though they
are created similarly to other artificial neurons in the neural network.
Neural Network Algorithms
✓ The learning (or training) process in a neural network is started by separating the data into three groups:
theknowledgeacademy

Training dataset:
➢ The Neural Network can comprehend the weights between nodes thanks to this dataset.

Validation dataset:
➢ The Neural Network's performance is adjusted using this dataset.

Test data set:


➢ The accuracy and error margin of the neural network are evaluated using this dataset.
Convolutional Neural Networks(CNNs)
✓ Convolutional Neural Networks (CNNs) are a specialized type of neural networks that are
particularly effective for processing data with a grid-like topology, such as images. Example
theknowledgeacademy

✓ CNNs are designed to automatically and adaptively learn spatial hierarchies of features, from
low-level details to high-level patterns, through layers that process visual information in a
hierarchical fashion.

Key Components of CNNs:

➢ Convolutional Layers: These layers apply a set of learnable filters to the input. Each filter
captures specific features, and the output of each convolution operation is a feature map
that emphasizes the presence of detected features in the input.

➢ ReLU Layers: This activation function introduces non-linearity into the model, allowing it
to learn more complex patterns.

➢ Pooling Layers: These layers perform down-sampling operations to reduce the


dimensionality of the feature maps, thus decreasing the computational load, memory
usage, and the number of parameters.

➢ Fully Connected Layers: After several convolutional and pooling layers, the high-level
reasoning in the neural network is done via fully connected layers. Neurons in a fully
connected layer have connections to all activations in the previous layer.
Long Short Memory Network(LSTMs)
✓ Recurrent neural networks (RNNs) with long-term dependencies learning and adaptation capabilities are known as LSTMs. It can remember and
theknowledgeacademy

recall information from the past for a longer time, and by default, this is its only behaviour.
✓ Because LSTMs can hold onto memories or prior inputs, they are frequently used in time series predictions because they are built to retain
information over time.
✓ This comparison is made due to their chain-like structure, which consists of four interconnected layers that communicate with one another in
various ways.
✓ Along with time series prediction applications, they can be used to build speech recognizers, advance pharmaceutical research, and create
musical loops.
Recurrent Neural Networks(RNNs)
✓ Recurrent Neural Networks (RNNs) are a class of neural networks that are powerful for
modeling sequence data such as time series or natural language.
Example
theknowledgeacademy

✓ They are called recurrent because they perform the same task for every element of a sequence,
with the output being dependent on the previous computations.

✓ RNNs have a "memory" which captures information about what has been calculated so far,
essentially capturing information about the sequence's history to make predictions about what
comes next.

Key Components of RNNs:

➢ Input Layer: Takes sequence data as input.

➢ Hidden Layers: One or more layers where the recurrent computation happens, utilizing
weights, bias, and activation functions to process data. Each neuron in a hidden layer
maintains a hidden state which captures some information about the sequence.

➢ Output Layer: Produces the final output, which could be a vector in a classification task or
a continuous value in regression.
Generative Adversarial Networks(GANs)
✓ GANs are deep learning algorithms that produce new instances of data that closely resemble the training data.
theknowledgeacademy

✓ In a GAN, there are typically two parts: a generator that learns to produce false data and a discriminator that adjusts by taking lessons from
this false data.
✓ Since they are frequently used to sharpen astronomical images and simulate lensing the gravitational dark matter, GANs have grown
significantly in popularity over time.
✓ Additionally, by recreating 2D textures in a higher resolution, such as 4K, video games can increase the visual appeal of their 2D textures.
✓ They are also employed in the production of lifelike cartoon characters, as well as the rendering of human faces and 3D objects.
Radial Basis Function Networks(RBFN)
✓ Radial functions are used as activation functions in RBFNs, a subset of neural networks that employs Example
theknowledgeacademy

a feed-forward methodology.
✓ Input, hidden, and output layers make up their three layers, which are primarily used for time-series
prediction, regression analysis, and classification.
✓ By analysing the similarities found in the training data set, RBFNs perform these tasks.
✓ Typically, they have an input vector that sends these data into the input layer, validating the
identification and disseminating results by comparing prior data sets.
✓ The output's distance from the centre of the neuron is inversely proportional to the Gaussian
transfer functions in the hidden layer. The output layer consists of linear combinations of radial-
based data, where output is produced using Gaussian functions that are passed as parameters to
the neuron.
Multilayer Perceptrons (MLPs)
✓ A Multilayer Perceptron (MLP) is a type of feedforward artificial neural network that Example
consists of at least three layers: an input layer, one or more hidden layers, and an
theknowledgeacademy

output layer.

✓ MLPs use fully connected layers and nonlinear activation functions, making them
powerful for solving classification and regression problems.

Key Components:

➢ Input Layer: Takes the input features.

➢ Hidden Layers: Contain neurons connected to all neurons in the previous and
next layers, using activation functions to introduce non-linearity.

➢ Output Layer: Produces the final predictions.

➢ Activation Functions: Commonly used activation functions include ReLU,


sigmoid, or softmax.

➢ Loss Function: Determines how the error is computed during training.

➢ Optimizer: Updates weights during training (e.g., SGD, Adam).


Self Organising Maps(SOMs)
✓ Teuvo Kohenen created SOMs in order to visualise data and comprehend its dimensions using artificial, self-organizing neural networks.
theknowledgeacademy

✓ In order to solve problems, attempts are made to visualise data that is primarily impossible for humans to see.
✓ Because these data are typically multidimensional, there are fewer opportunities for human error and involvement.
✓ SOMs aid in data visualisation by choosing random vectors from the provided training data after initialising the weights of various nodes.
✓ So that dependencies can be understood, they look at each node to determine the relative weights. The best matching unit is used to
determine the winning node (BMU).
✓ The RGB colour combinations that we employ in our daily tasks are one example of such. To comprehend how they work, consider the
illustration below.
Deep Belief Networks(DBNs)
✓ Because DBNs have multiple layers of latent and stochastic variables, they are also known as generative models.
theknowledgeacademy

✓ Because the latent variable has binary values, it is referred to as a hidden unit. Because the RGM layers are stacked on top of one another to
establish communication with earlier and later layers, DBNs are also known as Boltzmann Machines.
✓ Applications like video and image recognition as well as the capture of moving objects use DBNs.
✓ DBNs are powered by Greedy algorithms.
✓ The most typical way DBNs operate is by leaning through a top-down approach to generate weights in layers. On the top hidden two-layer, DBNs
employ a step-by-step Gibbs sampling method.
Restricted Boltzmann Machine(RBMs)
✓ RBMs are stochastic neural networks that learn from the probability distribution in the given input set.
theknowledgeacademy

✓ They were created by Geoffrey Hinton. This algorithm is primarily employed in the areas of topic modelling, regression, and classification, as
well as in the reduction of dimension.
✓ The visible layer and the hidden layer are the two layers that make up RBIs.
✓ Both of these layers have bias units connected to nodes that produce the output and are connected by hidden units. RBMs typically consist of
two phases: forward pass and backward pass.
✓ By accepting inputs and converting them to numbers, RBMs carry out their function of encoding inputs in the forward pass. Every input is
weighted by RBMs, and the backward pass takes these weights and further translates them into reconstructed inputs.
Artificial Neural Networks(ANNs)
✓ Artificial Neural Network is derived from Biological neural networks that develop the structure of a human brain.
theknowledgeacademy

✓ Artificial neural networks also have neurons that are interconnected to one another in different layers of the networks, much like the human
brain, which has neurons that are interconnected to one another.
✓ Theses neurons are known as nodes.
✓ Artificial neural networks are used in artificial intelligence to simulate the network of neurons that make up the human brain, giving computers
the ability to comprehend information and make decisions in a manner similar to that of a human.
✓ Computers are programmed to behave exactly like a network of interconnected brain cells to create an artificial neural network.
Feed Forward Neural Network
✓ A feed-forward neural network, also known as an artificial neural network, prevents the formation of cycles between the nodes.
theknowledgeacademy

✓ All of the perceptrons in this type of neural network are arranged in layers, with the input layer receiving input and the output layer producing
output.
✓ The term "hidden layers" refers to those layers that are not connected to the outside world. Each node in the layer below is connected to one of
the perceptrons that are contained in that layer.
✓ The feed-forward network is free of back-loops. The backpropagation algorithm can be used to update the weight values and reduce prediction
error.

✓ Applications:
❑ Data Compression
❑ Pattern Recognition
❑ Computer Vision
❑ Sonar Target Recognition
❑ Speech Recognition
❑ Handwritten Characters Recognition
Autoencoders
✓ A special kind of neural network called an autoencoder finds inputs and outputs that are typically identical.
theknowledgeacademy

✓ It was created primarily to address issues with unsupervised learning. Highly trained neural networks called autoencoders replicate the data.
✓ The input and output are typically the same because of it. They are employed to carry out tasks like population prediction, image processing,
and drug discovery.
✓ The encoder, the code, and the decoder are the three parts that make up an autoencoder. The design of autoencoders allows them to take in
inputs and convert them into a variety of representations.
✓ Reconstructing the original input is a more accurate method of copying it. They accomplish this by reducing the size and encoding the image or
input.
MNIST
✓ A sizable database of handwritten numbers or digits called the MNIST (Modified National Institute of Standards and Technology) database is
theknowledgeacademy

used to train various image processing systems.


✓ The dataset is also frequently used for machine learning training and testing. Two NIST databases, Special Database 1 and Special Database 3,
were combined to create the collection of images in the MNIST database.
✓ 10,000 testing images and 60,000 training images make up the MNIST dataset.
✓ The MNIST dataset, which is essentially a database of different handwritten digits, is accessible online.
✓ Large amounts of data from the MNIST dataset are frequently used to show off the true power of deep neural networks.
✓ To recognise any numbered image, our eyes and brain must cooperate.
✓ Our mind is a powerful tool that can quickly classify any image. A number can take on a variety of shapes, and while our minds can quickly
identify these shapes and ascertain what number they represent, a computer would find it more difficult to accomplish the same task.
MNIST(Fig)
✓ There is only one method for doing this, and that is to employ deep neural networks, which allow us to effectively train computers to classify
theknowledgeacademy

handwritten digits.
✓ The MNIST dataset, which has multiple levels and ten classes, allows us to categorise numbers from 0 to 9. The way that MNIST data is fed into
a neural network is the main distinction between the dataset and those that we have previously used.
MNIST
✓ A single data point in the MNIST dataset is represented by an image.
theknowledgeacademy

✓ The 28*28 pixel images in the MNIST dataset are typical examples, with 28 pixels crossing both the horizontal axis and the vertical axis.
✓ This indicates that a single image from the MNIST database requires analysis of a total of 784 pixels. Our neural network's input layer has 784
nodes that can be used to explain one of these images.
Deep Learning Applications
theknowledgeacademy

1 Self-Driving Cars

2 Voice Controlled Assistance

3 Automatic Image Capture Generation

4 Automatic Machine Translation


Congratulations
Congratulations on completing this module!
Contact Us
info@[Link]

[Link]/tickets

[Link]

theknowledgeacademy

You might also like