0% found this document useful (0 votes)
4 views13 pages

Classification Techniques Overview

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)
4 views13 pages

Classification Techniques Overview

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

[Link]@gmail.

com
R8L0PN473F
Classification

This file is meant for personal use by [Link]@[Link] only.


Sharing or publishing the contents in part or full is liable for legal action.
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
Topics covered so far
1. Intro: Classification

2. Gaussian Models

3. Logistic Regression

4. Performance Assessments
[Link]@[Link]
R8L0PN473F

5. K-Nearest Neighbors

This file is meant for personal use by [Link]@[Link] only.


Sharing or publishing the contents in part or full is liable for legal action.
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited. 2
Discussion questions
1. Why do we use logistic regression?
2. What is a confusion matrix and how can you interpret it?
3. Why is accuracy not always a good performance measure?
4. How to choose the threshold using the Precision-Recall curve?
5. Is there a performance measure that can cover both Precision and Recall?
[Link]@[Link]
R8L0PN473F
6. How does the K-NN algorithm work? How to identify K in this algorithm?

This file is meant for personal use by [Link]@[Link] only.


Sharing or publishing the contents in part or full is liable for legal action.
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited. 3
Why do we use logistic regression?
● Logistic Regression is a supervised learning algorithm that is used for classification problems, i.e., where the
dependent variable is categorical.
● In logistic regression, we use the Sigmoid function to calculate the probability of the dependent variable.
● The real-life applications of logistic regression are churn prediction, spam detection, etc.
● The below image shows how logistic regression is different from linear regression in fitting the model.

[Link]@[Link]
R8L0PN473F

This file is meant for personal use by [Link]@[Link] only.


Sharing or publishing the contents in part or full is liable for legal action. Image Source
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited. 4
Confusion matrix
It is used to measure the performance of a classification
algorithm. It can be used to calculate the following metrics:
Actual Values
1. Accuracy: Proportion of correctly predicted results
among the total number of observations Positive (1) Negative (0)

Accuracy = (TP+TN)/(TP+FP+FN+TN)
[Link]@[Link]
Positive (1) TP FP

Predicted Values
R8L0PN473F
2. Precision: Proportion of true positives to all the
predicted positives, i.e., how valid the predictions are

Precision = (TP)/(TP+FP)
Negative (0) FN TN
3. Recall: Proportion of true positives to all the actual
positives, i.e., how complete the predictions are

Recall = (TP)/(TP+FN)
This file is meant for personal use by [Link]@[Link] only.
Sharing or publishing the contents in part or full is liable for legal action.
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited. 5
Why accuracy is not always a good performance measure
Accuracy is simply the overall % of correct predictions and can be high even for very useless models.

# Total
Model Misses out on
Patients – 100
Cancer rate – predicts that Accuracy – 2 critical
# of Patients
2% no one has 98% patients
having cancer
cancer having cancer
-2

Here, accuracy
[Link]@[Link]

R8L0PN473F
will be 98%, even if we simply ● The other important metrics are Recall and
predict that every patient does not have cancer. Precision:
● In this case, Recall should be used as a measure of ○ Recall - What % of actuals 1s did the model
model performance; high recall imply fewer false capture in prediction?
negatives. ○ Precision - What % of predicted 1s are
● Fewer false negatives implies a lower chance of actual 1s?
‘missing’ a cancer patient, i.e., predicting a cancer ● There is a tradeoff - as you try to increase the
patient as one not having cancer. Recall, the Precision will reduce and vice versa.
● This is where we need other metrics to evaluate ● This tradeoff can be used to figure out the right
model performance. threshold to use for the model.

This file is meant for personal use by [Link]@[Link] only.


Sharing or publishing the contents in part or full is liable for legal action.
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited. 6
How to chose thresholds using the Precision-Recall curve?
● The Precision-Recall curve is a useful measure of
the success of prediction when the classes are
imbalanced.
● The curve shows the tradeoff between the precision
and the recall for different thresholds.
● It can be used to select an optimal threshold as
required to improve the model performance.
[Link]@[Link]
● Here, as we can see, the precision and the recall are
R8L0PN473F
almost equal when the threshold is around 0.4.
● If we want a higher precision, we can increase the
threshold.
● If we want a higher recall, we can decrease the
Choosing different thresholds can
threshold.
completely change the model’s
performance.
It is important to think about what
constitutes the ‘sweet spot’.

This file is meant for personal use by [Link]@[Link] only.


Sharing or publishing the contents in part or full is liable for legal action.
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited. 7
Is there a performance measure that can cover both Precision
and Recall?

● F1 Score is a measure that takes into account both Precision and Recall.
● The F1 Score is the harmonic mean of Precision and Recall. Therefore, this score takes both false positives and false
negatives into account.

[Link]@[Link]
R8L0PN473F

● The highest possible value of the F1 score is 1, indicating perfect precision and recall, and the lowest possible value is
0.

This file is meant for personal use by [Link]@[Link] only.


Sharing or publishing the contents in part or full is liable for legal action.
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited. 8
K-Nearest Neighbours (K-NN) algorithm
This algorithm uses features from the training data to predict the values of new data points, which means the
new data point will be assigned a value based on how similar it is to the data points in the training set. We can
define its working in the following steps:
● Step 1: We need to choose the value of K, i.e., the number of nearest data points to consider. K can be any
positive integer.
● Step 2: For each point in the test data do the following:
Calculate the distance between the test point and each training point with the help of any of the
[Link]@[Link]
R8L0PN473F○
distance methods, namely: Euclidean, Manhattan, etc. The most commonly used method to calculate
the distance is the Euclidean method.
○ Now, based on the distance value, sort them in ascending order.
○ Next, choose the top K rows from the sorted array.
○ Now, assign a class to the test point based on the most frequent class.
● Step 3: Repeat this process until all the test points are classified in a
particular class.
We try different values of K and plot them against the test error. The lower the
value of the test error, the better the
This file value
is [Link] use by [Link]@[Link] only.
Sharing or publishing the contents in part or full is liable for legal action.
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited. 9
[Link]@[Link]
R8L0PN473F Case Study

This file is meant for personal use by [Link]@[Link] only.


Sharing or publishing the contents in part or full is liable for legal action.
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited. 10
[Link]@[Link]
R8L0PN473F Appendix

This file is meant for personal use by [Link]@[Link] only.


Sharing or publishing the contents in part or full is liable for legal action.
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited. 11
LDA vs QDA

Linear Discriminant Analysis Quadratic Discriminant Analysis

It is a linear classifier but much less It is a non-linear classifier but more flexible
flexible than QDA than LDA

It assumes a common covariance matrix for It assumes that each class has its
R8L0PN473F all the classes covariance matrix
[Link]@[Link]

It is preferred when the training set only It is preferred when the training set is very
has a few observations large

It can be used as a dimensionality It cannot be used as a dimensionality


reduction technique reduction technique

This file is meant for personal use by [Link]@[Link] only.


Sharing or publishing the contents in part or full is liable for legal action.
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited. 12
Happy Learning !
[Link]@[Link]
R8L0PN473F

This file is meant for personal use by [Link]@[Link] only.


Sharing or publishing the contents in part or full is liable for legal action. 13
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.

Common questions

Powered by AI

LDA assumes equal covariance matrices across different classes, leading to a linear decision boundary. This assumption reduces model complexity and is appropriate for cases where classes have similar scatter characteristics. QDA, however, allows each class to have its own covariance matrix, supporting quadratic decision boundaries and offering greater flexibility. This makes QDA more capable of capturing complex class distributions but also increases model complexity, requiring more data to accurately estimate the parameters .

Accuracy can be misleading in scenarios with class imbalance. For example, if only 2% of a dataset contains positive cases (e.g., cancer patients) and the model predicts all cases as negative, it will achieve 98% accuracy despite failing to identify actual positives. In such cases, metrics like recall and precision are more informative as they account for false negatives and false positives respectively, offering insights into the model's competence in identifying the rare class .

K-Nearest Neighbors classifies a data point by considering the 'K' nearest neighbors from the training data. The steps include selecting K, computing the distance from the test point to all training points, sorting these distances, and determining the most frequent class among the top 'K' neighbors to assign it to the test point. The choice of K impacts model accuracy; it is often selected by testing various values and evaluating their performance on the validation dataset to find the one minimizing error .

In imbalanced datasets, accuracy might not reflect true performance as it could be inflated by the majority class. Precision and Recall provide a clearer picture by focusing on the model's ability to correctly identify positive instances. Precision emphasizes the quality of positive predictions (limiting false positives), while Recall emphasizes detection of actual positives (limiting false negatives). Together, they offer a more nuanced evaluation of a model’s effectiveness in handling the minority class, which is often of greater interest .

LDA and QDA differ primarily in their assumptions about data distribution. LDA assumes a common covariance matrix across classes, fitting a linear decision boundary, and is less flexible but suitable for smaller datasets. QDA, however, assumes class-specific covariance matrices, allowing for more flexible decision boundaries and is preferred for larger datasets. LDA can also be used for dimensionality reduction, whereas QDA cannot .

Logistic Regression is used for classification problems because it models probabilities that the target variable belongs to a certain category. It uses the Sigmoid function to ensure the output probabilities range between 0 and 1, suitable for binary classification tasks such as churn prediction and spam detection. Unlike linear regression, Logistic Regression does not predict continuous outputs but rather the likelihood of class membership .

The confusion matrix allows for the calculation of various metrics that evaluate classification performance beyond simple accuracy. It provides counts of true positives, true negatives, false positives, and false negatives. These values are then used to compute metrics such as precision, recall, and the F1 score, which offer a deeper understanding of an algorithm's predictive quality, especially in imbalanced datasets .

The F1 Score harmonizes precision and recall into a single metric, providing a balanced measure especially useful when the class distribution is imbalanced. It is the harmonic mean of precision and recall, effectively accounting for both false positives and false negatives. This balance makes it ideal for assessing the trade-offs a model makes between these two metrics, ensuring a more comprehensive evaluation than either measure alone .

The Precision-Recall curve illustrates the trade-off between precision and recall for different thresholds in a classification model. By plotting these metrics, one can observe how changing the threshold impacts model performance. The optimal threshold is selected by determining what balance of precision and recall works best for the specific application context. A threshold providing a equilibrated precision-recall point might be favored, or the choice can lean towards higher precision or recall depending on the priority of fewer false positives or fewer false negatives .

The Sigmoid function in logistic regression transforms the linear combination of input features into a probability value between 0 and 1, denoting class membership. This non-linear transformation differs from linear functions, which map inputs directly to potentially unbounded outputs. The Sigmoid curve allows logistic regression to output the likelihood of a categorical outcome, enabling it to serve effectively in binary classification problems .

You might also like