Unit II Deep Learning
Unit II Deep Learning
The main difference between Regression and Classification algorithms that Regression
algorithms are used to predict the continuous values such as price, salary, age, etc. and
Classification algorithms are used to predict/Classify the discrete values such as Male
or Female, True or False, Spam or Not Spam, etc.
Classification:
Classification is a process of finding a function which helps in dividing the dataset into
classes based on different parameters. In Classification, a computer program is trained on
the training dataset and based on that training, it categorizes the data into different
classes.
The task of the classification algorithm is to find the mapping function to map the input(x)
to the discrete output(y).
Example: The best example to understand the Classification problem is Email Spam
Detection. The model is trained on the basis of millions of emails on different parameters,
and whenever it receives a new email, it identifies whether the email is spam or not. If the
email is spam, then it is moved to the Spam folder.
o Logistic Regression
o K-Nearest Neighbours
o Support Vector Machines
o Kernel SVM
o Naïve Bayes
o Decision Tree Classification
o Random Forest Classification
Regression:
Regression is a process of finding the correlations between dependent and independent
variables. It helps in predicting the continuous variables such as prediction of Market
Trends, prediction of House prices, etc.
The task of the Regression algorithm is to find the mapping function to map the input
variable(x) to the continuous output variable(y).
Example: Suppose we want to do weather forecasting, so for this, we will use the
Regression algorithm. In weather prediction, the model is trained on the past data, and
once the training is completed, it can easily predict the weather for future days.
In Regression, the output variable must In Classification, the output variable must be a
be of continuous nature or real value. discrete value.
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 input value(x) with the discrete output variable(y).
continuous output variable(y).
Regression Algorithms are used with Classification Algorithms are used with discrete data.
continuous data.
In Regression, we try to find the best fit In Classification, we try to find the decision boundary,
line, which can predict the output more which can divide the dataset into different classes.
accurately.
The regression Algorithm can be further The Classification algorithms can be divided into
divided into Linear and Non-linear Binary Classifier and Multi-class Classifier.
Regression.
Maximum Likelihood
Introduction
In this article, we will discuss the likelihood function, the core idea behind that,
and how it works with code examples. This will help one to understand the concept
better and apply the same when needed.
Let us dive into the likelihood first to understand the maximum likelihood
estimation.
For example. Suppose there are two data points in the dataset. The likelihood of
the first data point is greater than the second. In that case, it is assumed that
the first data point provides accurate information to the final model, hence being
likable for the model being informative and precise.
After this discussion, a gentle question may appear in your mind, If the working
of the likelihood function is the same as the probability function, then what is the
difference?
Although the working and intuition of both probability and likelihood appear to be
the same, there is a slight difference, here the possibility is a function that defines
or tells us how accurate the particular data point is valuable and contributes to
the final algorithm in data distribution and how likely is to the machine learning
algorithm.
Whereas probability, in simple words is a term that describes the chance of some
event or thing happening concerning other circumstances or conditions, mostly
known as conditional probability.
Also, the sum of all the probabilities associated with a particular problem is one
and can not exceed it, whereas the likelihood can be greater than one.
Noe here, if we try to solve the same problem with the help of maximum likelihood
estimation, the function will first calculate the probability of every data point
according to every suitable condition for the target variable. In the next step, the
function will plot all the data points in the two-dimensional plots and try to find
the line that best fits the dataset to divide it into two parts. Here the best-fit line
will be achieved after some epochs, and once achieved, the line is used to classify
the data point by simply plotting it to the graph.
The maximum likelihood estimation is a base of some machine learning and deep
learning approaches used for classification problems. One example is logistic
regression, where the algorithm is used to classify the data point using the best-
fit line on the graph. The same approach is known as the perceptron trick
regarding deep learning algorithms.
As shown in the above image, all the data observations are plotted in a two-
dimensional diagram where the X-axis represents the independent column or the
training data, and the y-axis represents the target variable. The line is drawn to
separate both data observations, positives and negatives. According to the
algorithm, the observations that fall above the line are considered positive, and
data points below the line are regarded as negative data points.
import pandas as pd
import numpy as np
import seaborn as sns
from sklearn.linear_model import LogisticRegression
lr=LogisticRegression()
lr.fit(X_train,y_train)
lr_pred=lr.predict(X_test)
sns.regplot(x="X",y='lr_pred',data=df_pred ,logistic=True, ci=None)
The above code will fit the logistic regression for the given dataset and generate
the line plot for the data representing the distribution of the data and the best fit
according to the algorithm.
Key Takeaways
Maximum Likelihood is a function that describes the data points and their likeliness to
the model for best fitting.
Maximum likelihood is different from the probabilistic methods, where probabilistic
methods work on the principle of calculation probabilities. In contrast, the likelihood
method tries o maximize the likelihood of data observations according to the data
distribution.
Maximum likelihood is an approach used for solving the problems like density
distribution and is a base for some algorithms like logistic regression.
The approach is very similar and is predominantly known as the perceptron trick in
terms of deep learning methods.
Logistic Regression
Logistic regression is a supervised machine learning algorithm used
for classification tasks where the goal is to predict the probability that an instance
belongs to a given class or not. Logistic regression is a statistical algorithm which analyze
the relationship between two data factors. The article explores the fundamentals of
logistic regression, it’s types and implementations.
For example, we have two classes Class 0 and Class 1 if the value of the logistic function
for an input is greater than 0.5 (threshold value) then it belongs to Class 1 it belongs to
Class 0. It’s referred to as regression because it is the extension of linear regression but is
mainly used for classification problems.
Key Points:
Logistic regression predicts the output of a categorical dependent variable.
Therefore, the outcome must be a categorical or discrete value.
It can be either Yes or No, 0 or 1, true or False, etc. but instead of giving the
exact value as 0 and 1, it gives the probabilistic values which lie between 0 and
1.
In Logistic regression, instead of fitting a regression line, we fit an “S” shaped
logistic function, which predicts two maximum values (0 or 1).
Logistic Function – Sigmoid Function
The sigmoid function is a mathematical function used to map the predicted
values to probabilities.
It maps any real value into another value within a range of 0 and 1. The value
of the logistic regression must be between 0 and 1, which cannot go beyond
this limit, so it forms a curve like the “S” form.
The S-form curve is called the Sigmoid function or the logistic function.
In logistic regression, we use the concept of the threshold value, which defines
the probability of either 0 or 1. Such as values above the threshold value tends
to 1, and a value below the threshold values tends to 0.
Types of Logistic Regression
On the basis of the categories, Logistic Regression can be classified into three types:
1. Binomial: In binomial Logistic regression, there can be only two possible types
of the dependent variables, such as 0 or 1, Pass or Fail, etc.
Sigmoid function
As shown above, the figure sigmoid function converts the continuous variable data into
the probability i.e. between 0 and 1.
tends towards 1 as
tends towards 0 as