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

Scaler's Machine Learning Course

The document provides an overview of machine learning, detailing its significance, types, and applications across various industries. It categorizes machine learning into supervised, unsupervised, semi-supervised, and reinforcement learning, each with distinct methodologies, advantages, and challenges. Additionally, it promotes Scaler's Machine Learning course for those looking to enhance their skills in this field.

Uploaded by

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

Scaler's Machine Learning Course

The document provides an overview of machine learning, detailing its significance, types, and applications across various industries. It categorizes machine learning into supervised, unsupervised, semi-supervised, and reinforcement learning, each with distinct methodologies, advantages, and challenges. Additionally, it promotes Scaler's Machine Learning course for those looking to enhance their skills in this field.

Uploaded by

Syed Sariya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 66

ML:

Machine learning, a subset of artificial


intelligence, empowers computers to learn
from data and make predictions or decisions.
Its significance in today’s world is undeniable,
with applications spanning various industries.
The three main types—supervised learning
(learning from labeled data), unsupervised
learning (finding patterns in unlabeled data),
and reinforcement learning (learning through
trial and error)—enable a wide range of
applications, from image recognition and
natural language processing to
recommendation systems and fraud detection.
As data creation escalates, the relevance and
impact of machine learning continue to
expand.
Dive into the world of machine learning with
Scaler’s Machine Learning course. Enroll
now to master the skills needed to drive
innovation and make a significant impact in
various industries!

Types of Machine Learning

Machine learning algorithms are broadly


classified into four categories based on their
learning style and the nature of the data they
handle, as follows:
● Supervised Machine Learning
● Unsupervised Machine Learning
● Semi-Supervised Machine Learning
● Reinforcement Learning

1. Supervised Machine Learning


In supervised learning, models learn from
labeled datasets, where the input data is paired
with the correct output. This enables the
model to learn patterns and make predictions
or classifications based on new input data.
● Classification: In classification, the goal
is to categorize data points into predefined
classes or labels. Examples include spam
filtering, sentiment analysis, and image
recognition. Common algorithms used in
classification are:
● Decision Trees

● Support Vector Machines (SVM)

● Naive Bayes

● Random Forests

● Regression: Regression tasks involve


predicting continuous values, such as
prices, temperatures, or sales figures.
Examples include stock price prediction,
demand forecasting, and house price
estimation. Popular regression algorithms
include:
● Linear Regression

● Polynomial Regression

● Ridge Regression

● Lasso Regression

● Advantages: Supervised learning offers


high accuracy and provides clear guidance
for predictions.
● Disadvantages: The primary challenge
with supervised learning is the necessity
for extensive labeled datasets, which are
costly and labor-intensive to prepare.
Additionally, training sophisticated models
demands significant computational
resources.
● Applications: This technique is widely
applied in various fields, including, but not
limited to:
● Spam detection in communication

systems
● Credit scoring for financial
assessments
● Medical diagnosis to enhance
treatment accuracy
● Predicting customer churn in business
analytics

2. Unsupervised Machine Learning


Unsupervised learning involves training
models on unlabeled data, where the
algorithm identifies patterns and structures in
the data without explicit guidance.
● Clustering: Clustering algorithms group

similar data points together into clusters


based on their inherent similarities.
Examples include customer segmentation,
market basket analysis, and anomaly
detection. Common clustering algorithms
include:
● K-means

● Hierarchical Clustering

● DBSCAN

● Association: Association rule learning


aims to discover interesting relationships
between variables in large datasets. An
example is market basket analysis, which
identifies products frequently purchased
together. Popular algorithms for
association rule learning include:
● Apriori Algorithm: Identifies frequent

item sets and extends them to larger


ones as long as they meet the desired
frequency.
● Eclat Algorithm: Uses a depth-first

search technique to improve efficiency


over the Apriori algorithm.
● Advantages: Unsupervised learning
doesn’t require labeled data and can
uncover hidden patterns and relationships
in the data.
● Disadvantages: The results of
unsupervised learning can be less
interpretable and harder to validate than
those of supervised learning.
● Applications: Unsupervised learning is
used in applications such as:
● Market basket analysis

● Customer segmentation

● Recommendation systems

● Anomaly detection

3. Semi-Supervised Learning
Semi-supervised learning combines elements
of both supervised and unsupervised learning.
It utilizes a small amount of labeled data along
with a large amount of unlabeled data to train
models.
● Methods: Semi-supervised learning

algorithms often use a combination of


techniques, such as:
● Self-training

● Co-training

● Graph-based methods

● Advantages: It can leverage both labeled

and unlabeled data, reducing the need for


large amounts of labeled data, which can
be costly and time-consuming to acquire.
● Disadvantages: It still requires some

labeled data, and the algorithms can be


more complex to implement than purely
supervised or unsupervised methods.
● Applications: Semi-supervised learning is

applied in tasks like:


● Web content classification

● Protein sequence classification

● Speech recognition
Take your understanding of machine learning
techniques to the next level with Scaler’s
Machine Learning course. Enroll now to
master the skills that will set you apart in the
field of artificial intelligence!

4. Reinforcement Learning
Reinforcement learning is a type of machine
learning where an agent learns to make
decisions by interacting with an environment
and receiving rewards or penalties based on its
actions. The goal is to learn a policy that
maximizes the cumulative reward over time.
● Types: Reinforcement learning involves
two main types of feedback:
● Positive Reinforcement: The agent

receives rewards for actions that are


deemed beneficial or desirable within
the context of the given goals.
● Negative Reinforcement: The agent

incurs penalties for actions that are


considered detrimental or undesirable,
discouraging such behaviors in future
scenarios.
● Advantages: Reinforcement learning can
learn optimal actions through trial and
error, making it effective for complex
problems where explicit instructions are
difficult to provide.
● Disadvantages: It can require a lot of data
and computational resources to train,
especially for complex environments.
● Applications: Reinforcement learning is
utilized in a variety of advanced
applications, including:
● Robotics: For tasks such as navigation

and manipulation where robots learn to


perform tasks in unpredictable
environments.
● Game AI: Notably in programs like

AlphaGo, where the system learns


strategies in complex games like Go
beyond human capabilities.
● Autonomous Systems: In self-driving

cars, reinforcement learning helps in


making real-time navigation decisions
based on dynamic road conditions.

Conclusion
In conclusion, understanding the various types
of machine learning – supervised,
unsupervised, semi-supervised, and
reinforcement – is crucial for anyone
venturing into this dynamic field. Each type
offers unique strengths and applications,
catering to different data scenarios and
objectives.
Supervised learning excels in prediction and
classification tasks, while unsupervised
learning uncovers hidden patterns and
structures in unlabeled data. Semi-supervised
learning bridges the gap between the two,
leveraging both labeled and unlabeled data,
while reinforcement learning enables agents to
learn optimal actions through trial and error.
Overview
Supervised Machine Learning is the way in which a model is
trained with the help of labeled data, wherein the model
learns to map the input to a particular output.
Unsupervised Machine Learning is where a model is
presented with unlabeled data, and the model is made to
work on it without prior training and thus holds great
potential on real-world labelless datasets.

What is Supervised Machine Learning?


Supervised Machine Learning involves training a model with
labeled data. By labeled data, we mean that the data should
have a clear mapping between the input features (X) and the
output variable (Y).

As we train/teach our model with this mapping, it is called


'supervised' learning.

The basic principle of supervised machine learning is to have


a model that has learned a set of mappings in a generalized
manner such that it can generate correct labels (or outputs)
for new data that it has never seen. The model is trained until
it makes the minimum possible error.

Some examples of supervised Machine Learning in real-life


applications may be:

● Face detection/recognition.
● Weather forecasting.
● Spam Detection.
● Stock price prediction.
Working of Supervised Learning
Let us understand the working of supervised Machine
Learning with the help of an example:

Think of it as teaching a toddler about what is a cat or a dog,


or maybe what are the different kinds of fruits. What you
may want to do is, show the kid pictures and videos of cats
and dogs (or show them in person what a cat/dog looks like).

You may tell them about the features and characteristics of it.
Such as a cat has whiskers and meows, a dog barks, etc. You
may show them what cats and dogs look like.
Next time, when you ask them to identify whether the animal
is a cat or a dog, and if the kid is able to identify it correctly,
this means you successfully taught them!

If not, you'll help them identify it correctly by showing more


examples, and eventually, they will learn what a cat/dog
looks like.

This is the same way supervised learning works. Following


is the way in which formally Supervised Learning works:

A Supervised Learning model is trained with labeled data


and is allowed to learn the underlying relationship between
the input features and output variable.

Once the training is complete, we test the performance of our


model with test data, which is new for the model, i.e., the
data is unseen. Test data is usually part of the training set,
which we keep separately for testing our model. We perform
the testing using different loss functions and other metrics. It
keeps adjusting its parameters until good accuracy is
achieved, and the model starts giving satisfactory results
even on unseen data.
Now that we have a basic understanding of Supervised
Learning, let us discuss its types.

Types of Supervised Learning


Broadly, supervised learning is of two types:

1. Regression.
2. Classification.
Regression is the kind of supervised learning that learns from
labeled data and predicts continuous-valued output
corresponding to a given input. Examples of such continuous
outputs may be height, amount of money, etc.
Classification is the kind of supervised learning that learns
from labeled data and is used to predict a particular class
corresponding to a given input. An example of an output
class can be 'cat' or 'dog' to classify if the given picture is of a
cat or a dog.

Regression
Regression is a type of Supervised Machine Learning that we
use to understand and map the statistical relationship
between the predictor and response variables. This is
generally useful with numerical data such as sales revenue
and temperature trends.

The following are the major types of regression algorithms:

● Linear Regression: In this type of supervised learning,


the model aims to find the underlying
relationship/pattern between the independent variables
(X) and the dependent variable (Y) by plotting a best-fit
line, which is (in most cases) determined by the method
of least squares.
○ Simple Linear Regression: This is the type of linear
regression is used when we apply our model to find
the underlying relationship between a single
independent variable and a single output variable.
○ Multi-linear Regression: This is similar to the
simple linear regression, just the difference being
that the number of independent variables, in this
case, is more than one.
● Logistic Regression: Contrary to linear regression, in the
case of logistic regression, the model aims to solve the
problems of classifications such as problems that have
outcomes like 'True' or 'False,' '0' or '1' or even multiple
categories. Each category is assigned a probability
between 0 to 1, where all probabilities of all classes sum
up to 1.

Classification
Classification is the type of Supervised Machine Learning
that we use to categorize our output into one of the defined
categories, such as 'spam' or 'not spam,' 'masked' or 'not
masked' etc.

Classification can be done into two or more than two


categories, therefore the broad categories: binary and multi-
class classification.

An example of a binary classification will be to classify if an


e-mail is a spam or not spam. Same way, an example of
multi-class classification can be taken as a classification of
dog breeds.
Following are a few examples of classification algorithms:

● Support Vector Machines: SVMs are the most


commonly used models to determine clear
separations/classifications of our data points.
● Decision Trees: As the name suggests, these are models
that represent a tree, where each node represents a
condition, and the branches represent the agreement or
disagreement to the condition.
● Random Forest: It involves the usage of multiple
uncorrelated decision trees, whose results are combined
in the end to extract the best predictions.
Advantages and Disadvantages of
Supervised Learning
● Advantages
○ Supervised Learning's biggest advantage is that we
can have a directed end-point to our problem. We
can make the model focus clearly on the output
classes that we define or desire to classify into.
○ Supervised learning helps with a lot of predictive
tasks, where we can make best use of past data to
generate predictions corresponding to new data.
○ When accuracy and correct classification are
crucial factors for our problem, supervised learning
models are the best choice.
● Disadvantages
○ Training over large datasets makes Supervised
Learning a computationally expensive and time-
consuming process.
○ While knowing the classes we want to classify our
data into prior to working on our model is
considered an advantage in Supervised learning, in
cases when the output classes are not known, it can
be one of the drawbacks carries.
○ Data pre-processing is a big challenge while
working with supervised learning algorithms.

What is Unsupervised Machine Learning?


Contrary to Supervised learning, Unsupervised Learning
involves presenting the model with unlabelled data. This
means that the data does not have any labels or categories,
and there is no training involved. This type of learning can
be considered as learning without any guidance. The model
is left open to learning on its own by detecting the co-
relations between the features without any expected output.

The basic principle of unsupervised learning is to learn in the


absence of any ground truth to compare our model with. The
idea is to use the underlying patterns in the data to generate a
reconstruction of the input data in a useful format. By
'underlying patterns in the data, we mean that the data is then
explained on the basis of similarities, hidden patterns, etc.,
all without any human intervention.
Some examples of unsupervised Machine Learning in real-
life applications may be:

● Recommendation Systems.
● Customer segmentation.
● DNA clustering.
Working of Unsupervised Learning:
Let us understand the working of unsupervised Machine
Learning with the help of an example:

Suppose we give our model unlabeled images of red-colored


fruits, such as pomegranates, apples, and plums. Our model
hasn't seen or known any kind of fruits before and will now
try to categorize the images on the basis of similarities and
differences in the structure and appearance only. We will let
the model discover the hidden patterns in the data itself.

Combine these two according to the first picture with a fruit


example.
Same way, in recommendation systems, unsupervised
learning algorithms help cluster commodities that are
frequently bought together.

This further helps the sellers to provide recommendations to


the buyers, many of which we have seen quite a lot of times
on online selling platforms such as "Frequently bought
together" and "Customers who bought this, also bought this."

Now that we have a basic understanding of Unsupervised


Learning, let us discuss its types.

Types of Unsupervised Learning


Unsupervised learning is mainly of two types:

1. Clustering.
2. Association.
Clustering or cluster analysis is used when we want to group
our dataset on the basis of inherent similarities in the data.

Association rules are used when we are trying to explain the


dependence relationship between the data that are usually
seen together. In simple words, we may want to explain the
dependence of how Y happens after X happens, i.e.: X -> Y.

Clustering
Cluster analysis is the most common method used in
Unsupervised Learning. We tend to perform cluster analysis
on our dataset when we are working with unlabeled data,
wherein our model discovers patterns on its own without any
human intervention.

The objects in our data with similarities are grouped into a


cluster, and different clusters have objects with different
characteristics.

Let us understand the analogy of clustering with an example.


Consider a group of people who are provided with a fruit
basket with different types of fruits. They are then asked to
group (or arrange) the fruits in different categories. They are
not given any criteria for grouping, so there is no correct
grouping that needs to be done.
Someone may group the fruits according to their taste, such
as sweet, tangy, etc. Some may group the fruits according to
their color, such as yellow, red, etc.

For every person, there might be a different cluster they may


put fruit into. This is how clustering works too. Even with no
task set, there might be various hidden patterns that cluster
analysis may unfold.

There are mainly three types of clustering:

● Hard Clustering: Also known as exclusive clustering,


wherein one part of data can only belong to one cluster
only.
An example of a Hard Clustering algorithm can be taken
as K-means clustering. It is the most common type of
iterative clustering performed where the data objects are
put into K number of clusters.
K is the input parameter, and accordingly, the data items are
assigned to the nearest cluster center and are done iteratively
until the clusters are formed properly. One data point belongs
to one cluster only.

● Soft Clustering: Also known as overlapping clustering,


wherein one part of data can be a part of more than one
cluster.
An example of a Soft Clustering algorithm can be taken
as Fuzzy K-means clustering, where one data point is
not bound to a single cluster. There may be cases when
due to this reason, the clusters may overlap with each
other.

● Hierarchical Clustering: In this type, the model tends to


create a hierarchy of clusters. Working with hierarchy
can happen in two ways:
○ Agglomerative hierarchical clustering: This is also
known as bottom-up custering. In this kind of
hierarchical clustering, every data point is
considered a cluster, and based on the distance
between the points, they are merged iteratively until
the combined clusters end up in a single cluster of
all data points.
○ Divisive hierarchical clustering: This is also known
as top-down clustering. This is the complete
opposite of agglomerative clustering, where we
start from one whole cluster and iteratively perform
splits to perform separate clusters until we reach
every data point as a separate cluster.
Association
Association rules are used when we want to find the
dependence of one data item on another, such as X->Y,
which means if X, then Y. One of the most common
examples of association rules may be the video
recommendation that we get after watching any video.
For example, on Netflix, when we watch a movie, we are
provided with recommendations of similar movies under the
tab "Because you watched this, you may also like it."

Application of association rules to transaction data can prove


to be very useful for increasing sales and hence, profit. This
is known as Market Basket Analysis, which is often used by
retail companies.

We may find several hidden relationships about the items


that are frequently bought together, such as computer
systems and anti-virus software, bread, and milk, or a set of
more than two items as well, such as vegetables that are
frequently bought together. This leads to the companies
having clearer insights as to what items the customers buy
together.

Advantages and Disadvantages of Unsupervised


Learning
● Advantages
○ Given the unavailability of labeled data and the
huge amount of uncategorized data all around the
world, Unsupervised Learning can prove to be very
useful in drawing the best insights from data in all
possible domains, such as healthcare, education,
finances, etc.
○ At times when the output classes are not defined,
and we do not know what relationship the data
items hold, unsupervised learning algorithms help
discover the categories in the data.
● Disadvantages
○ Sometimes, we may have a different goal from
what our model finds in the data. This may lead to a
waste of computational resources and time.
○ Since there is no ground truth to compare the model
outputs with, we cannot make sure if our model is
performing well or not. This, in turn, leads to less
accurate results.

Supervsed Learning v/s. Unsupervised


Learning
Now that we have discussed all Supervised and
Unsupervised Learning, let us compare them to understand
which type of learning we should pick for the best outcomes.

● Evaluate the type of data at hand. According to the data


being labeled or unlabeled, choose Supervised or
Unsupervised learning, respectively.
● Find out the level of human intervention your problem
requires. In the case of Supervised Learning, we may
have the ground truth and evaluation metrics to assess
our model. In the case of Unsupervised Learning, we
may require subject matter experts to assess if our
model is performing well.
● Define a goal for your problem. Is there a particular
direction you want your model to into? Are there pre-
defined ground truths? Then Supervised Learning is
what you should go with. On the other hand, if the
problem statement at hand allows you to be open to
discovering new patterns and insights, then
Unsupervised Learning will help.
● Research about related problems. Research similar use
cases and see what solutions were built up earlier and
what kind of Machine Learning algorithms proved to be
useful.
Conclusion
● With the great rise in Machine Learning in recent years,
key Supervised and Unsupervised Learning algorithms
are proving to be the most useful and helpful when it
comes to even the most complex problems.
● While Supervised Learning involves supervision with
labeled data, it paves the way for predictive tasks that
can make the best use of past data to generate
predictions for the future.
● On the other hand, Unsupervised Learning opens doors
for tasks where we may find surprising results about the
hidden patterns in the data.

Regression in Machine Learning


Overview
Machine learning fundamentally has two segments:
supervised and unsupervised learning. While supervised
learning deals with labeled data, unsupervised learning deals
with unlabelled ones. Supervised learning can be further
segmented into classification and regression. The key
difference between them is that classification deals with
discrete values while regression deals with continuous
values. This article revolves around Regression in Machine
Learning and its related models.

Introduction
What is Regression Analysis?
Regression analysis is a statistical method that helps us to
model the relationship between dependent variables and one
or more independent variables. This analysis helps us to
understand the change in the value of our target variable
corresponding to an independent variable when other
independent variables are held fixed. It predicts
continuous/real values such as salary, prices, temperature,
etc.

The different types of regression in machine learning


analysis techniques are involved when the target variable
with continuous values and independent variables show a
linear or non-linear relationship with each other.
In other words, regression analysis involves determining the
best-fit line, which is a line that passes through all the data
points in such a way that the distance of the line from each
data point is minimal.

What are Regression Models in Machine


Learning?
Regression in Machine Learning is a supervised learning
technique and is used for prediction, forecasting, time series
modeling, and exploratory data analysis (determining the
causal-effect relationship between variables). There are
several regression analysis techniques depending on the
number of factors involved.
● Linear regression
● Logistic regression
● Ridge Regression
● Lasso Regression
● Polynomial regression
● Support Vector Regression
● Decision Tree Regression
● Random Forest Regression
ML – Different Regression types

It is a form of predictive modelling technique which investigates the relationship


between a dependent (target) and independent variable (s) (predictor). To establish the
possible relationship among different variables, various modes of statistical
approaches are implemented, known as regression analysis. Basically, regression
analysis sets up an equation to explain the significant relationship between one or
more predictors and response variables and also to estimate current observations.
Regression model comes under the supervised learning, where we are trying to predict
results within a continuous output, meaning that we are trying to map input variables
to some continuous function. Predicting prices of a house given the features of the
house like size, price etc is one of the common examples of Regression

Types of regression in ML

● Linear Regression : Linear regression attempts to model the relationship


between two variables by fitting a linear equation to observed data. One
variable is considered to be an explanatory variable, and the other is
considered to be a dependent variable.It is represented by an equation:
Y = a + b*X + e

where a is intercept, b is slope of the line and e is error term. This equation
can be used to predict the value of target variable based on given predictor
variable(s).This can be written much more concisely using a vectorized

form, as shown: where h? is the hypothesis function,


using the model parameters ?.
● Logistic Regression: Some regression algorithm can also be used for
classification.Logistic regression is commonly used to estimate the
probability that an instance belongs to a particular class. For example, what
is the probability that this email is spam?. If the estimated probability is
greater than 50% then the instance belongs to that class called the positive
class(1) or else it predicts that it does not then it belongs to the negative
class(0). This makes it a binary classification. In order to map predicted
values to probabilities, we use the sigmoid function. The function maps any
real value into another value between 0 and 1.
y = 1/(1 + e(-x)).

This linear relationship can be written in the following mathematical form:

● Polynomial Regression: What if our data is actually more complex than a


simple straight line? Surprisingly, we can actually use a linear model to fit
nonlinear data. A simple way to do this is to add powers of each feature as
new features, then train a linear model on this extended set of features. This
technique is called Polynomial Regression.The equation below represents a
polynomial equation:
● Softmax Regression: The Logistic Regression model can be generalized to
support multiple classes directly, without having to train and combine
multiple binary classifiers . This is called Somax Regression, or
Multinomial Logistic Regression.The idea is quite simple: when given an
instance x, the Softmax Regression model first computes a score sk(x) for
each class k, then estimates the probability of each class by applying the
somax function (also called the normalized exponential) to the

scores.Equation for softmax regression:


● Ridge Regression: Rigid Regression is a regularized version of Linear
Regression where a regularized term is added to the cost function. This
forces the learning algorithm to not only fit the data but also keep the model
weights as small as possible. Note that the regularized term should not be
added to the cost function during training. Once the model is trained, you
want to evaluate the model’s performance using the unregularized
performance measure. The formula for rigid regression is:

● Lasso Regression: Similar to Ridge Regression, Lasso (Least Absolute


Shrinkage and Selection Operator) is another regularized version of Linera
regression : it adds a regularized term to the cost function, but it uses the l1
norm of the weighted vector instead of half the square of the l2 term Lasso

regression is given as:


● Elastic Net Regression: ElasticNet is middle ground between Lasso and
Ridge Regression techniques.The regularization term is a simple mix of
both Rigid and Lasso’s regularization term. when r=0, Elastic Net is
equivalent to Rigid Regression and when r=1, Elastic Net is equivalent to
Lasso Regression.The expression for Elastic Net Regression is given as:

● Need for regression:


● If we want to do any sort of data analysis on the given data, we need to
establish a proper relationship between the dependent and independent
variables to do predictions which forms the basis of our evaluation. And that
relationships are given by the regression models and thus they form the core
for any data analysis.
● Gradient Descent:
● Gradient Descent is a very generic optimization algorithm capable of
finding optimal solutions to a wide range of problems. The general idea of
Gradient Descent is to tweak parameters iteratively in order to minimize a
cost function. Here that function is our Loss Function. The loss is the error
in our predicted value of m(slope) and c(constant). Our goal is to minimize
this error to obtain the most accurate value of m and c. We will use the
Mean Squared Error function to calculate the loss. There are three steps in
this function:
1. Find the difference between the actual y and predicted y value(y =
mx + c), for a given x.
2. Square this difference.
3. Find the mean of the squares for every value in X.


● Here y is the actual value and y’ is the predicted value. Lets substitute the
value of y’:


● Now the above equation is minimized using the gradient descent algorithm
by partially differentiating it w.r.t m and c.


● Then finally we update the values of m and c as follow:

● Code: simple demonstration of Gradient Descent
● 1
● # Making the imports % matplotlib inline
● 2
● import pandas as pd
● 3
● import numpy as np
● 4
● import matplotlib as mpl
● 5
● import matplotlib.pyplot as plt
● 6
● X = np.arange(1, 7)
● 7
● Y = X**2
● 8
● plt.figure(figsize =(10, 10))
● 9
● plt.scatter(X, y, color ="yellow")
● 10
● plt.title('sample demonstration of gradient descent')
● 11
● plt.ylabel('squared value-y')
● 12
● plt.xlabel('linear value-x')
● Output:

scatter plot

● Code:
● 1
● m = 0
● 2
● c = 0
● 3

● 4
● L = 0.0001 # The learning Rate
● 5
● epochs = 1000 # The number of iterations to perform
gradient descent
● 6

● 7
● n = float(len(X)) # Number of elements in X
● 8

● 9
● # Performing Gradient Descent
● 10
● for i in range(epochs):
● 11
● # The current predicted value of Y
● 12
● Y_pred = m * X + c
● 13
● # Derivative wrt m
● 14
● D_m = (-2 / n) * sum(X * (Y - Y_pred))
● 15
● # Derivative wrt c
● 16
● D_c = (-2 / n) * sum(Y - Y_pred)
● 17
● # Update m
● 18
● m = m - L * D_m
● 19
● # Update c
● 20
● c = c - L * D_c
● 21

● 22
● print (m, c)
● Output:
● 4.471681318702568 0.6514172394787497
● Code:
● 1
● Y_pred = m * X + c
● 2
● plt.figure(figsize =(10, 10))
● 3
● plt.scatter(X, Y, color ="yellow")
● 4
● # regression line
● 5
● plt.plot([min(X), max(X)], [min(Y_pred), max(Y_pred)],
color ='red')
● 6
● plt.title('sample demonstration of gradient descent')
● 7
● plt.ylabel('squared value-y')
● 8
● plt.xlabel('linear value-x')
● 9
● plt.show()
● Output:

final result

List of Machine Learning Classification Algorithms


Classification algorithms organize and understand complex datasets in

machine learning. These algorithms are essential for categorizing data


into classes or labels, automating decision-making and pattern

identification. Classification algorithms are often used to detect email

spam by analyzing email content. These algorithms enable machines to

quickly recognize spam trends and make real-time judgments, improving

email security.

Some of the top-ranked machine learning algorithms for Classification

are:

1. Logistic Regression

2. Decision Tree

3. Random Forest

4. Support Vector Machine (SVM)

5. Naive Bayes

6. K-Nearest Neighbors (KNN)

Let us see about each of them one by one:

1. Logistic Regression Classification Algorithm in

Machine Learning
In Logistic regression is classification algorithm used to estimate discrete

values, typically binary, such as 0 and 1, yes or no. It predicts the

probability of an instance belonging to a class that makes it essectial for

binary classification problems like spam detection or diagnosing disease.


Logistic functions are ideal for classification problems since their output is

between 0 and 1. Many fields employ it because of its simplicity,

interpretability, and efficiency. Logistic Regression works well when

features and event probability are linear. Logistic Regression used for

binary classification tasks. Logistic regression is used for binary

categorization. Despite its name, it predicts class membership likelihood.

A logistic function models probability in this linear model.

Logistic Regression (Graph)

Features of Logistic Regression


1. Binary Outcome: Logistic regression is used when the dependent

variable is binary in nature, meaning it has only two possible

outcomes (e.g., yes/no, 0/1, true/false).

2. Probabilistic Results: It predicts the probability of the occurrence

of an event by fitting data to a logistic function. The output is a

value between 0 and 1, which represents the probability that a

given input belongs to the '1' category.

3. Odds Ratio: It estimates the odds ratio in the presence of more

than one explanatory variable. The odds ratio can be used to

understand the strength of the association between the

independent variables and the dependent binary variable.

4. Logit Function: Logistic regression uses the logit function (or

logistic function) to model the data. The logit function is an S-

shaped curve that can take any real-valued number and map it

into a value between 0 and 1.

2. Decision Tree
Decision Trees are versatile and simple classification and regression

techniques. Recursively splitting the dataset into key-criteria subgroups

provides a tree-like structure. Judgments at each node produce leaf

nodes. Decision trees are easy to understand and depict, making them

useful for decision-making. Overfitting may occur, therefore trimming


improves generality. A tree-like model of decisions and their

consequences, including chance event outcomes, resource costs and

utility.

The algorithm used for both classification and regression tasks. They

model decisions and their possible results as tree, with branches

representing choices and leaves representing outcomes.

Decision Tree

Features of Decision Tree

1. Tree-Like Structure: Decision Trees have a flowchart-like

structure, where each internal node represents a "test" on an


attribute, each branch represents the outcome of the test, and

each leaf node represents a class label (decision taken after

computing all attributes). The paths from root to leaf represent

classification rules.

2. Simple to Understand and Interpret: One of the main advantages

of Decision Trees is their simplicity and ease of interpretation.

They can be visualized, which makes it easy to understand how

decisions are made and explain the reasoning behind predictions.

3. Versatility: Decision Trees can handle both numerical and

categorical data and can be used for both regression and

classification tasks, making them versatile across different types

of data and problems.

4. Feature Importance: Decision Trees inherently perform feature

selection, giving insights into the most significant variables for

making the predictions. The top nodes in a tree are the most

important features, providing a straightforward way to identify

critical variables.

3. Random Forest
Random forest are an ensemble learning techniques that combines

multiple decision trees to improve predictive accuracy and control over-

fitting. By aggregating the predictions of numerous trees, Random Forests


enhance the decision-making process, making them robust against noise

and bias.

Random Forest uses numerous decision trees to increase prediction

accuracy and reduce overfitting. It constructs many trees and integrates

their predictions to create a reliable model. Diversity is added by using a

random dataset and characteristics in each tree. Random Forests excel at

high-dimensional data, feature importance metrics, and overfitting

resistance. Many fields use them for classification and regression.

Random Forest

Features of Random Forest


1. Ensemble Method: Random Forest uses the ensemble learning

technique, where multiple learners (decision trees, in this case)

are trained to solve the same problem and combined to get

better results. The ensemble approach improves the model's

accuracy and robustness.

2. Handling Both Types of Data: It can handle both categorical and

continuous input and output variables, making it versatile for

different types of data.

3. Reduction in Overfitting: By averaging multiple trees, Random

Forest reduces the risk of overfitting, making the model more

generalizable than a single decision tree.

4. Handling Missing Values: Random Forest can handle missing

values. When it encounters a missing value in a variable, it can

use the median for numerical variables or the mode for

categorical variables of all samples reaching the node where the

missing value is encountered.

4.Support Vector Machine (SVM)


SVM is an effective classification and regression algorithm. It seeks the

hyperplane that best classifies data while increasing the margin. SVM

works well in high-dimensional areas and handles nonlinear feature


interactions with its kernel technique. It is powerful classification

algorithm known for their accuracy in high-dimensional spaces

SVM is robust against overfitting and generalizes well to different

datasets. It finds applications in image recognition, text classification, and

bioinformatics, among other fields. Its use cases span image recognition,

text categorization, and bioinformatics, where precision is paramount.

Support Vector Machine

Feature of Support Vector Machine

1. Margin Maximization: SVM aims to find the hyperplane that

separates different classes in the feature space with the


maximum margin. The margin is defined as the distance between

the hyperplane and the nearest data points from each class,

known as support vectors. Maximizing this margin increases the

model's robustness and its ability to generalize well to unseen

data.

2. Support Vectors: The algorithm is named after these support

vectors, which are the critical elements of the training dataset.

The position of the hyperplane is determined based on these

support vectors, making SVMs relatively memory efficient since

only the support vectors are needed to define the model.

3. Kernel Trick: One of the most powerful features of SVM is its use

of kernels, which allows the algorithm to operate in a higher-

dimensional space without explicitly computing the coordinates

of the data in that space. This makes it possible to handle non-

linearly separable data by applying linear separation in this

higher-dimensional feature space.

4. Versatility: Through the choice of the kernel function (linear,

polynomial, radial basis function (RBF), sigmoid, etc.), SVM can

be adapted to solve a wide range of problems, including those

with complex, non-linear decision boundaries.

5.Naive Bayes
Text categorization and spam filtering benefit from Bayes theorem-based

probabilistic classification algorithm Naive Bayes. Despite its simplicity

and "naive" assumption of feature independence, Naive Bayes often

works well in practice. It uses conditional probabilities of features to

calculate the class likelihood of an instance. Naive Bayes handles high-

dimensional datasets quickly.

Naive Bayes which describes the probability of an event, based on prior

knowledge of conditions that might be related to the event. Naive Bayes

classifiers assume that the presence (or absence) of a particular feature of

a class is unrelated to the presence (or absence) of any other feature,

given the class variable

Features of Naive Bayes

1. Probabilistic Foundation: Naive Bayes classifiers apply Bayes'

theorem to compute the probability that a given instance belongs

to a particular class, making decisions based on the posterior

probabilities.

2. Feature Independence: The algorithm assumes that the features

used to predict the class are independent of each other given the

class. This assumption, although naive and often violated in real-


world data, simplifies the computation and is surprisingly

effective in practice.

3. Efficiency: Naive Bayes classifiers are highly efficient, requiring a

small amount of training data to estimate the necessary

parameters (probabilities) for classification.

4. Easy to Implement and Understand: The algorithm is

straightforward to implement and interpret, making it accessible

for beginners in machine learning. It provides a good starting

point for classification tasks.

6.K-Nearest Neighbors (KNN)


KNN uses the majority class of k-nearest neighbours for easy and

adaptive classification and regression. Non-parametric KNN has no data

distribution assumptions. It works best with uneven decision boundaries

and performs well for varied jobs. K-Nearest Neighbors (KNN) is an

instance-based, or lazy learning algorithm, where the function is only

approximated locally, and all computation is deferred until function

evaluation. It classifies new cases based on a similarity measure (e.g.,

distance functions). KNN is widely used in recommendation systems,

anomaly detection, and pattern recognition due to its simplicity and

effectiveness in handling non-linear data.


K-Nearest Algorithm

Fetures of K-Nearest Neighbors (KNN)

1. Instance-Based Learning: KNN is a type of instance-based or lazy

learning algorithm, meaning it does not explicitly learn a model.

Instead, it memorizes the training dataset and uses it to make

predictions.

2. Simplicity: One of the main advantages of KNN is its simplicity.

The algorithm is straightforward to understand and easy to

implement, requiring no training phase in the traditional sense.

3. Non-Parametric: KNN is a non-parametric method, meaning it

makes no underlying assumptions about the distribution of the


data. This flexibility allows it to be used in a wide variety of

situations, including those where the data distribution is

unknown or non-standard.

4. Flexibility in Distance Choice: The algorithm's performance can

be significantly influenced by the choice of distance metric (e.g.,

Euclidean, Manhattan, Minkowski). This flexibility allows for

customization based on the specific characteristics of the data.

Comparison of Top Machine Learning Classification

Algorithms
The top 6 Machine Learning Algorithms for Classification are compared in

this table:

Support
K-
Decision Random Naive Vector
Feature Ne
Tree Forest Bayes Machines
(
(SVM)

Type Tree-based Ensemble Probabilistic Margin-based Insta

Learning
(Bagging
model model model
model)

Categorical
Categorical or Categorical or
Output or Categorical Ca
Continuous Continuous
Continuous

Similar to

Decision Tree,
Assumes data
but assumes Assumes
is separable in Assum
that a feature
Assumptions Minimal a high- instan
combination of independenc
dimensional simila
models e
space
improves

accuracy

Simple, Handles Efficient, Effective in Simpl


Strengths
interpretabl overfitting works well high- fo

e, handles better than with high- dimensional dat


both
Decision
numerical
Trees, good dimensional spaces, mod
and
for large data versatile re
categorical
datasets
data

More complex Simplistic


Prone to Can be
and assumption Sens
overfitting, memory
computational can limit scale
Weaknesses not ideal for intensive,
ly intensive performance and
very large difficult to
than Decision on complex fe
datasets interpret
Trees problems
Classificatio
Large datasets Text Reco
n and Image
with high classification ns
regression recognition,
dimensionality , spam a
Use Cases tasks, text
, classification filtering, de
feature categorization,
and regression sentiment p
importance bioinformatics
tasks analysis rec
analysis

Slower than
Medium to Fast
Decision Tree
high, data
Training Time Fast due to Very fast
depending on fo
ensemble
kernel choice d
method

Medium (due High (simple Low (complex

Interpretability High to ensemble probabilistic transformation

nature) model) s)

Choosing the Right Algorithm for Your Data


The problem and dataset must be considered before choosing a machine

learning algorithm. Each algorithm has strengths and works for different

data and problems.

● Decision Trees and Random Forests for their versatility and ease

of use.

● Logistic Regression for binary classification problems.

● Support Vector Machines for high-dimensional data.

● K-Nearest Neighbors for its simplicity and effectiveness in

smaller datasets.

● Deep Learning models, like CNNs for image classification and

RNNs for sequence data, although more complex, are powerful

for high-dimensional data and complex problem spaces.

Conclusion
Classification methods from machine learning have transformed difficult

data analysis. For classification, this article examined the top six machine

learning algorithms: Decision Tree, Random Forest, Naive Bayes, Support

Vector Machines, K-Nearest Neighbors, and Gradient Boosting. Each

algorithm is useful for different categorization issues due to its distinct

properties and applications. Understanding these algorithms' strengths

and drawbacks helps data scientists and practitioners solve real-world

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy