Professional Documents
Culture Documents
Machine Learning
Machine Learning
Linear Regression
Linear regression is one of the basic statistical techniques in regression
analysis. People use it for investigating and modelling the relationship between
variables (i.e dependent variable and one or more independent variables).
Before being promptly adopted into machine learning and data science, linear
models were used as basic tools in statistics to assist prediction analysis and data
mining. If the model involves only one regressor variable (independent variable), it
is called simple linear regression and if the model has more than one regressor
variable, the process is called multiple linear regression.
Equation of Straight Line
Let’s consider a simple example of an engineer wanting to analyze the product
delivery and service operations for vending machines. He/she wants to determine
the relationship between the time required by a deliveryman to load a machine
and the volume of the products delivered. The engineer collected the delivery time
(in minutes) and the volume of the products (in a number of cases) of 25 randomly
selected retail outlets with vending machines. Scatter diagram is the observations
plotted on a graph.
Where,
Y: Dependent Variable
m: Slope
X: Independent Variable
c: y-intercept
Our aim here is to calculate the values of slope, y-intercept, and substitute them in
the equation along with the values of independent variable X, to determine the
values of dependent variable Y. Let’s assume that we have ‘n’ data points, then we
can calculate slope using the scary looking formula below:
Dept of CSE,ASGI B. Uma Maheswari
Assistant Professor
Then, y-intercept is calculated using the formula:
Step 1: First step is to calculate the slope ‘m’ using the formula
This way by the least squares regression method provides the closest relationship
between the dependent and independent variables by minimizing the distance
between the residuals (or error) and the trend line (or line of best fit). Therefore,
the sum of squares of residuals (or error) is minimal under this approach.
In the previous topic, we have learned about Simple Linear Regression, where a
single Independent/Predictor(X) variable is used to model the response variable (Y).
But there may be various cases in which the response variable is affected by more
than one predictor variable; for such cases, the Multiple Linear Regression
algorithm is used.
Mul ple Linear Regression is one of the important regression algorithms which
models the linear rela onship between a single dependent con nuous variable and
more than one independent variable.
MLR equation:
1. Y= b<sub>0</sub>+b<sub>1</sub>x<sub>1</sub>+ b<sub>2</sub>x<sub>
2</sub>+ b<sub>3</sub>x<sub>3</sub>+...... bnxn ............... (a)
Where,
Y= Output/Response variable
Perceptron model is also treated as one of the best and simplest types of Artificial
Neural networks. However, it is a supervised learning algorithm of binary classifiers.
Hence, we can consider it as a single-layer neural network with four main
parameters, i.e., input values, weights and Bias, net sum, and an activation
function.
Mr. Frank Rosenblatt invented the perceptron model as a binary classifier which
contains three main components. These are as follows:
This is the primary component of Perceptron which accepts the initial data into the
system for further processing. Each input node contains a real numerical value.
Weight parameter represents the strength of the connection between units. This is
another most important parameter of Perceptron components. Weight is directly
proportional to the strength of the associated input neuron in deciding the output.
Further, Bias can be considered as the line of intercept in a linear equation.
o Activation Function:
These are the final and important components that help to determine whether the
neuron will fire or not. Activation Function can be considered primarily as a step
function.
o Sign function
o Step function, and
o Sigmoid function
Step-1
In the first step first, multiply all input values with corresponding weight values and
then add them to determine the weighted sum. Mathematically, we can calculate
the weighted sum as follows:
Add a special term called bias 'b' to this weighted sum to improve the model's
performance.
∑wi*xi + b
Step-2
Y = f(∑wi*xi + b)
Based on the layers, Perceptron models are divided into two types. These are as
follows:
This is one of the easiest Artificial neural networks (ANN) types. A single-layered
perceptron model consists feed-forward network and also includes a threshold
Dept of CSE,ASGI B. Uma Maheswari
Assistant Professor
transfer function inside the model. The main objective of the single-layer
perceptron model is to analyze the linearly separable objects with binary
outcomes.
In a single layer perceptron model, its algorithms do not contain recorded data, so
it begins with inconstantly allocated input for weight parameters. Further, it sums
up all inputs (weight). After adding all inputs, if the total sum of all inputs is more
than a pre-determined value, the model gets activated and shows the output value
as +1.
Like a single-layer perceptron model, a multi-layer perceptron model also has the
same model structure but has a greater number of hidden layers.
o Forward Stage: Activation functions start from the input layer in the forward
stage and terminate on the output layer.
o Backward Stage: In the backward stage, weight and bias values are modified
as per the model's requirement. In this stage, the error between actual
output and demanded originated backward on the output layer and ended
on the input layer.
Perceptron Function
Perceptron function ''f(x)'' can be achieved as output by multiplying the input 'x'
with the learned weight coefficient 'w'.
f(x)=1; if w.x+b>0
otherwise, f(x)=0
Characteristics of Perceptron
Future of Perceptron
The future of the Perceptron model is much bright and significant as it helps to
interpret data by building intuitive patterns and applying them in the future.
Machine learning is a rapidly growing technology of Artificial Intelligence that is
continuously evolving and in the developing phase; hence the future of perceptron
technology will continue to support and facilitate analytical behavior in machines
that will, in turn, add to the efficiency of computers.
Support Vector Machine or SVM is one of the most popular Supervised Learning
algorithms, which is used for Classification as well as Regression problems.
However, primarily, it is used for Classification problems in Machine Learning.
The goal of the SVM algorithm is to create the best line or decision boundary that
can segregate n-dimensional space into classes so that we can easily put the new
data point in the correct category in the future. This best decision boundary is
called a hyperplane.
SVM chooses the extreme points/vectors that help in creating the hyperplane.
These extreme cases are called as support vectors, and hence algorithm is termed
as Support Vector Machine. Consider the below diagram in which there are two
different categories that are classified using a decision boundary or hyperplane:
Example: SVM can be understood with the example that we have used in the KNN
classifier. 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
Dept of CSE,ASGI B. Uma Maheswari
Assistant Professor
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. Consider the below diagram:
SVM algorithm can be used for Face detection, image classification, text
categorization, etc.
Types of SVM
o Linear SVM: Linear SVM is used for linearly separable data, which means if a
dataset can be classified into two classes by using a single straight line, then
such data is termed as linearly separable data, and classifier is used called as
Linear SVM classifier.
o 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.
The dimensions of the hyperplane depend on the features present in the dataset,
which means if there are 2 features (as shown in image), then hyperplane will be a
straight line. And if there are 3 features, then hyperplane will be a 2-dimension
plane.
We always create a hyperplane that has a maximum margin, which means the
maximum distance between the data points.
Support Vectors:
The data points or vectors that are the closest to the hyperplane and which affect
the position of the hyperplane are termed as Support Vector. Since these vectors
support the hyperplane, hence called a Support vector.
Linear SVM:
Hence, the SVM algorithm helps to find the best line or decision boundary; this best
boundary or region is called as a hyperplane. SVM algorithm finds the closest point
of the lines from both the classes. These points are called support vectors. 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:
So to separate these data points, we need to add one more dimension. For linear
data, we have used two dimensions x and y, so for non-linear data, we will add a
third dimension z. It can be calculated as:
z=x2 +y2
By adding the third dimension, the sample space will become as below image:
Since we are in 3-d Space, hence it is looking like a plane parallel to the x-axis. If we
convert it in 2d space with z=1, then it will become as:
The Naïve Bayes algorithm is comprised of two words Naïve and Bayes, Which can
be described as:
Bayes' Theorem:
o 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.
o The formula for Bayes' theorem is given as:
Where,
Working of Naïve Bayes' Classifier can be understood with the help of the below
example:
Problem: If the weather is sunny, then the Player should play or not?
Outlook Play
0 Rainy Yes
1 Sunny Yes
2 Overcast Yes
3 Overcast Yes
4 Sunny No
5 Rainy Yes
7 Overcast Yes
8 Rainy No
9 Sunny No
10 Sunny Yes
11 Rainy No
12 Overcast Yes
13 Overcast Yes
Weather Yes No
Overcast 5 0
Rainy 2 2
Sunny 3 2
Total 10 5
Weather No Yes
Rainy 2 2 4/14=0.29
Sunny 2 3 5/14=0.35
P(Yes|Sunny)= P(Sunny|Yes)*P(Yes)/P(Sunny)
P(Sunny)= 0.35
P(Yes)=0.71
P(No|Sunny)= P(Sunny|No)*P(No)/P(Sunny)
P(Sunny|NO)= 2/4=0.5
P(No)= 0.29
P(Sunny)= 0.35
o Naïve Bayes is one of the fast and easy ML algorithms to predict a class of
datasets.
o It can be used for Binary as well as Multi-class Classifications.
o It performs well in Multi-class predictions as compared to the other
Algorithms.
o It is the most popular choice for text classification problems.
There are three types of Naive Bayes Model, which are given below:
Kernel methods' fundamental premise is used to convert the input data into a high-
dimensional feature space, which makes it simpler to distinguish between classes
or generate predictions. Kernel methods employ a kernel function to implicitly map
The most popular kind of kernel approach is the Support Vector Machine (SVM), a
binary classifier that determines the best hyperplane that most effectively divides
the two groups. In order to efficiently locate the ideal hyperplane, SVMs map the
input into a higher-dimensional space using a kernel function.
Other examples of kernel methods include kernel ridge regression, kernel PCA, and
Gaussian processes. Since they are strong, adaptable, and computationally
efficient, kernel approaches are frequently employed in machine learning. They are
resilient to noise and outliers and can handle sophisticated data structures like
strings and graphs.
Because the linear classifier can solve a very limited class of problems, the kernel
trick is employed to empower the linear classifier, enabling the SVM to solve a
larger class of problems.
The kernel function in SVMs is essential in determining the decision boundary that
divides the various classes. In order to calculate the degree of similarity between
any two points in the feature space, the kernel function computes their dot
product.
The most commonly used kernel function in SVMs is the Gaussian or radial basis
function (RBF) kernel. The RBF kernel maps the input data into an infinite-
dimensional feature space using a Gaussian function. This kernel function is popular
because it can capture complex nonlinear relationships in the data.
Other types of kernel functions that can be used in SVMs include the polynomial
kernel, the sigmoid kernel, and the Laplacian kernel. The choice of kernel function
depends on the specific problem and the characteristics of the data.
Basically, the choice of kernel function depends on the specific problem and the
characteristics of the data, and selecting an appropriate kernel function can
significantly impact the performance of machine learning algorithms.
In Support Vector Machines (SVMs), there are several types of kernel functions that
can be used to map the input data into a higher-dimensional feature space. The
choice of kernel function depends on the specific problem and the characteristics
of the data.
Linear Kernel
1. K(x, y) = x .y
Where x and y are the input feature vectors. The dot product of the input vectors
is a measure of their similarity or distance in the original feature space.
Polynomial Kernel
Where x and y are the input feature vectors, c is a constant term, and d is the degree
of the polynomial, K(x, y) = (x. y + c)d. The constant term is added to, and the dot
product of the input vectors elevated to the degree of the polynomial.
The decision boundary of an SVM with a polynomial kernel might capture more
intricate correlations between the input characteristics because it is a nonlinear
hyperplane.
The polynomial kernel has the benefit of being able to detect both linear and
nonlinear correlations in the data. It can be difficult to select the proper degree of
the polynomial, though, as a larger degree can result in overfitting while a lower
degree cannot adequately represent the underlying relationships in the data.
In general, the polynomial kernel is an effective tool for converting the input data
into a higher-dimensional feature space in order to capture nonlinear correlations
between the input characteristics.
The Gaussian kernel, also known as the radial basis function (RBF) kernel, is a
popular kernel function used in machine learning, particularly in SVMs (Support
Where x and y are the input feature vectors, gamma is a parameter that controls
the width of the Gaussian function, and ||x - y||^2 is the squared Euclidean
distance between the input vectors.
One advantage of the Gaussian kernel is its ability to capture complex relationships
in the data without the need for explicit feature engineering. However, the choice
of the gamma parameter can be challenging, as a smaller value may result in under
fitting, while a larger value may result in over fitting.
Laplace Kernel
The Laplacian kernel, also known as the Laplace kernel or the exponential kernel, is
a type of kernel function used in machine learning, including in SVMs (Support
Vector Machines). It is a non-parametric kernel that can be used to measure the
similarity or distance between two input feature vectors.
Where x and y are the input feature vectors, gamma is a parameter that controls
the width of the Laplacian function, and ||x - y|| is the L1 norm or Manhattan
distance between the input vectors.
One advantage of the Laplacian kernel is its robustness to outliers, as it places less
weight on large distances between the input vectors than the Gaussian kernel.
However, like the Gaussian kernel, choosing the correct value of the gamma
parameter can be challenging.
1. Classification
2. Regression
3. Clustering
4. Anomaly detection
5. Feature extraction
6. Natural language processing
7. Computer vision
8. Time series analysis
9. Recommender systems
10.Bio-informatics
11.Signal processing
12.Robotics