PDF&Rendition=1 2
PDF&Rendition=1 2
Machine Learning
Introduction to Machine Learning
• A subset of artificial intelligence known as machine learning focuses primarily on the
creation of algorithms that enable a computer to independently learn from data and
previous experiences.
• Machine Learning is the field of study that gives computers the capability to learn
without being explicitly programmed.
• Machine learning algorithms create a mathematical model that, without being explicitly
programmed, aids in making predictions or decisions with the assistance of sample
historical data, or training data.
• A machine learning system builds prediction models, learns from previous data, and
predicts the output of new data whenever it receives it. The amount of data helps to
build a better model that accurately predicts the output, which in turn affects the
accuracy of the predicted output.
• Let's say we have a complex problem in which we need to make predictions. Instead of
writing code, we just need to feed the data to generic algorithms, which build the logic
based on the data and predict the output. Our perspective on the issue has changed as a
result of machine learning. The Machine Learning algorithm's operation is depicted in
the following block diagram:
1. Supervised learning
2. Unsupervised learning
3. Semi supervised learning
4. Reinforcement learning
1) Supervised Learning
• In supervised learning, sample labelled data are provided to the machine learning
system for training, and the system then predicts the output based on the training data.
• The system uses labelled data to build a model that understands the datasets and learns
about each one. After the training and processing are done, we test the model with
sample data to see if it can accurately predict the output.
• The mapping of the input data to the output data is the objective of supervised learning.
• Spam filtering is an example of supervised learning.
• Supervised learning can be grouped further in two categories of algorithms:
i) Classification: A classification problem is when the output variable is a
category, such as “Red” or “blue” , “disease” or “no disease”.
ii) Regression: A regression problem is when the output variable is a real
value, such as “dollars” or “weight”.
Regression
Regression is a type of supervised learning that is used to predict continuous values, such as
house prices, stock prices, or customer churn. Regression algorithms learn a function that maps
from the input features to the output value.
Some common regression algorithms include:
Linear Regression
Polynomial Regression
Classification
Classification is a type of supervised learning that is used to predict categorical values, such as
whether a customer will churn or not, whether an email is spam or not, or whether a medical
image shows a tumour or not. Classification algorithms learn a function that maps from the
input features to a probability distribution over the output classes.
Some classification algorithms includes:
KNN, Logistic regression, Decision trees
The task of the regression algorithm is to The task of the classification algorithm is to map the
map the input value (x) with the continuous input value(x) with the discrete output variable(y).
output variable(y).
Regression Algorithms are used with Classification Algorithms are used with discrete data.
continuous data.
Regression algorithms can be used to solve Classification Algorithms can be used to solve
the regression problems such as Weather classification problems such as Identification of spam
Prediction, House price prediction, etc. emails, Speech Recognition, Identification of cancer
cells, etc.
2) Unsupervised Learning
• Unsupervised learning is a learning method in which a machine learns without any
supervision.
• The training is provided to the machine with the set of data that has not been labelled,
classified, or categorized, and the algorithm needs to act on that data without any
supervision.
• The goal of unsupervised learning is to restructure the input data into new features or a
group of objects with similar patterns.
• In unsupervised learning, we don't have a predetermined result. The machine tries to
find useful insights from the huge amount of data.
• Example: Imagine you have a machine learning model trained on a large dataset of
unlabelled images, containing both dogs and cats. The model has never seen an image
of a dog or cat before, and it has no pre-existing labels or categories for these animals.
Your task is to use unsupervised learning to identify the dogs and cats in a new, unseen
image.
3) Semi-Supervised Learning
• Semi-supervised learning is a type of machine learning that falls in between supervised
and unsupervised learning. It is a method that uses a small amount of labelled data and
a large amount of unlabelled data to train a model.
• Example: Text classification: In text classification, the goal is to classify a given text
into one or more predefined categories. Semi-supervised learning can be used to train
a text classification model using a small amount of labelled data and a large amount of
unlabelled text data.
4) Reinforcement Learning
• In reinforcement learning, the agent interacts with the environment and explores it. The
goal of an agent is to get the most reward points, and hence, it improves its performance.
• Reinforcement learning is a feedback-based learning method, agent learns
automatically with these feedbacks and improves its performance.
• Example: Automated robots, Traffic control etc.,
The main differences between Supervised and Unsupervised learning are given below:
Supervised learning algorithms are trained using Unsupervised learning algorithms are trained using
labelled data. unlabelled data.
In supervised learning, input data is provided to the In unsupervised learning, only input data is provided
model along with the output. to the model.
The goal of supervised learning is to train the model The goal of unsupervised learning is to find the
so that it can predict the output when it is given new hidden patterns and useful insights from the
data. unknown dataset.
Supervised learning model produces an accurate Unsupervised learning model may give less accurate
result. result as compared to supervised learning.
Supervised learning needs supervision to train the Unsupervised learning does not need any supervision
model. to train the model.
Decision Tree
• Decision Tree is a Supervised learning technique that can be used for both classification
and Regression problems, but mostly it is preferred for solving Classification problems.
It is a tree-structured classifier, where internal nodes represent the features of a dataset,
branches represent the decision rules and each leaf node represents the outcome.
• In a Decision tree, there are two nodes, which are the Decision Node and Leaf Node.
Decision nodes are used to make any decision and have multiple branches, whereas
Leaf nodes are the output of those decisions and do not contain any further branches.
• It is a graphical representation for getting all the possible solutions to a
problem/decision based on given conditions.
• It is called a decision tree because, similar to a tree, it starts with the root node, which
expands on further branches and constructs a tree-like structure.
• A decision tree simply asks a question, and based on the answer (Yes/No), it further
split the tree into subtrees.
• Root Node: Root node is from where the decision tree starts. It represents the entire
dataset, which further gets divided into two or more homogeneous sets.
• Leaf Node: Leaf nodes are the final output node, and the tree cannot be segregated
further after getting a leaf node.
• Splitting: Splitting is the process of dividing the decision node/root node into sub-
nodes according to the given conditions.
• Branch/Sub Tree: A tree formed by splitting the tree.
• Pruning: Pruning is the process of removing the unwanted branches from the tree.
• Parent/Child node: The root node of the tree is called the parent node, and other nodes
are called the child nodes.
Example: Let us take an example of playing football based on the weather condition. The
given table gives the data set.
In order to build a decision tree first we need to find out the entropy and Information Gain
(IG). The formula and calculations are given in the below image.
• It is simple to understand as it follows the same process which a human follow while
making any decision in real-life.
• It can be very useful for solving decision-related problems.
• It helps to think about all the possible outcomes for a problem.
• There is less requirement of data cleaning compared to other algorithms.
Disadvantages of the Decision Tree
Linear Regression
• Linear regression is one of the easiest and most popular Machine Learning algorithms.
• It is a statistical method that is used for predictive analysis. Linear regression makes
predictions for continuous/real or numeric variables such as sales, salary, age, product
price, etc.
• Linear regression algorithm shows a linear relationship between a dependent (y) and
one or more independent (y) variables, hence called as linear regression.
• Since linear regression shows the linear relationship, which means it finds how the
value of the dependent variable is changing according to the value of the independent
variable.
SAHANA K BGS FGC Mysuru
• The linear regression model provides a sloped straight line representing the relationship
between the variables.
Example: Pizza price detection based on the diameter using linear regression
The K-NN working can be explained on the basis of the below algorithm:
Step-1: Select the number K of the neighbours
Step-2: Calculate the Euclidean distance of K number of neighbours
Step-3: Take the K nearest neighbours as per the calculated Euclidean distance.
Step-4: Among these k neighbours, count the number of the data points in each category.
Step-5: Assign the new data points to that category for which the number of the neighbour is
maximum.
Step-6: Our model is ready.
Bayes' Theorem:
Bayes' theorem is also known as Bayes' Rule or Bayes' law, which is used to determine the
probability of a hypothesis with prior knowledge. It depends on the conditional probability.
The formula for Bayes' theorem is given as:
Example: From the given data set we need to predict the person having flu and covid is
having fever r not. The below image shows the calculation
Example: Suppose we see a strange cat that also has some features of dogs, so if we want a
model that can accurately identify whether it is a cat or dog, so such a model can be created by
using the SVM algorithm. We will first train our model with lots of images of cats and dogs so
that it can learn about different features of cats and dogs, and then we test it with this strange
creature. So as support vector creates a decision boundary between these two data (cat and dog)
and choose extreme cases (support vectors), it will see the extreme case of cat and dog. On the
basis of the support vectors, it will classify it as a cat.
Non-linear SVM: Non-Linear SVM is used for non-linearly separated data, which means if a
dataset cannot be classified by using a straight line, then such data is termed as non-linear data
and classifier used is called as Non-linear SVM classifier.
Hence, the SVM algorithm helps to find the best line or decision boundary; this best boundary
or region is called as a hyperplane.
The distance between the vectors and the hyperplane is called as margin. And the goal of SVM
is to maximize this margin. The hyperplane with maximum margin is called the optimal
hyperplane.
Non-Linear SVM:
If data is linearly arranged, then we can separate it by using a straight line, but for non-linear
data, we cannot draw a single straight line. Consider the below image:
So now, SVM will divide the datasets into classes in the following way. Consider the below
image:
Dendrites Inputs
Synapse Weights
Axon Output
2) Multilayer feed-forward network: This layer has a hidden layer that is internal to the
network and has no direct contact with the external layer. The existence of one or more
hidden layers enables the network to be computationally stronger, a feed-forward
network because of information flow through the input function, and the intermediate
computations used to determine the output.
3) Single node with its own feedback: When outputs can be directed back as inputs to
the same layer or preceding layer nodes, then it results in feedback networks. Recurrent
networks are feedback networks with closed loops.
5) Multilayer recurrent network: In this type of network, processing element output can
be directed to the processing element in the same layer and in the preceding layer
forming a multilayer recurrent network.