Notes Final
Notes Final
Machine Learning is the science of making computers learn patterns from past data so
they can predict or decide on new, unseen data.
Real-Life Examples
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Sample Raw Dataset (Collected from sources like Google Forms, CSV, or
database)
Problems:
• Missing values
• Duplicate data
After Cleaning
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
What we did:
Location Encoded
Pune 0
Mumbai 1
Delhi 2
Final Dataset
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Example:
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Prediction:
Input:
• Area = 2000
• Bedrooms = 4
• Location = Mumbai
Output:
Compare:
• Actual = 8200000
• Error = small → Good model
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
New Input:
Model Output:
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Feature Selection
Simple Meaning:
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
• Features (X):
o Area
o Bedrooms
o Location
• Target (Y):
o Price
Types of Features
1. Numerical Features
a. Example: Age, Salary, Area
2. Categorical Features
a. Example: City, Gender, Color
3. Derived Features
a. Created from existing data
b. Example: Price per [Link]
Feature Selection is the process of choosing only important features from the dataset
and removing unnecessary ones.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Definition:
Selecting the most relevant input variables to improve model performance
Example
Original Data:
We have Removed:
• Owner Name
• Phone Number
1. Improves Accuracy
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
2. Reduces Overfitting
3. Faster Training
4. Better Understanding
Feature Selection is the process of selecting the most relevant input features and removing
irrelevant or redundant ones to improve model performance.
2. Objectives
1. Improve accuracy
2. Reduce overfitting
3. Decrease training time
4. Improve interpretability
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
1. Filter Methods
2. Wrapper Methods
3. Embedded Methods
1. Filter Methods
• Filter methods are based on statistical techniques and do not require a machine learning model.
Each feature is evaluated independently.
Definition
• Formula
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Meaning of Symbols
1. r
2. x
3. y
4. x̄ (x-bar)
x̄ = (Σx) / n
5. ȳ (y-bar)
ȳ = (Σy) / n
6. (x − x̄)
7. (y − ȳ)
8. Σ (Sigma)
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Step-by-Step Example
Given Data
X (Experience) Y (Salary)
1 10
2 20
3 30
1. x̄ = (1 + 2 + 3) / 3 = 2
2. ȳ = (10 + 20 + 30) / 3 = 20
1. Σ(x−x̄)(y−ȳ) = 10 + 0 + 10 = 20
2. Σ(x−x̄)² = 1 + 0 + 1 = 2
3. Σ(y−ȳ)² = 100 + 0 + 100 = 200
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
r = 20 / √(2 × 200)
r = 20 / √400
r = 20 / 20
r=1
4. Final Answer
1. r = 1
2. This means perfect positive correlation
5. Interpretation
Simple Understanding
1. If X increases and Y increases → positive correlation
2. If X increases and Y decreases → negative correlation
3. If no pattern → zero correlation
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
NOTE:
1. Definition
2. Purpose
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
3. Formula
4. Meaning of Terms
• O (Observed Value)
• Actual value from dataset
• E (Expected Value)
• Value expected if there is no relationship
• Σ (Sigma)
• Sum of all values
5. Step-by-Step Example
Problem
1. Check whether Gender affects product purchase
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Expected Table
• (60 − 50)² / 50 = 2
Female Buy
• (60 − 50)² / 50 = 2
• (40 − 50)² / 50 = 2
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
2. Wrapper Methods
1. Wrapper methods use a machine learning model to evaluate different combinations of features.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
3. Embedded Methods
Embedded methods perform feature selection inside the model training process. The model itself
decides which features are important while learning.
Definition
Lasso (Least Absolute Shrinkage and Selection Operator) adds an L1 penalty (sum of absolute values of
coefficients) to the ordinary linear regression cost function.
This penalty shrinks some coefficients exactly to zero, automatically removing those features.
Cost Function
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Result: Lasso automatically removes OwnerName and HouseID. The final model uses only 3 features →
simpler and less overfitting.
Advantages
Disadvantages
Definition
Importance is measured by how much a feature reduces impurity (Gini or Entropy) across all splits.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
How It Works
• At every node, the tree picks the feature that gives the largest impurity reduction.
• Feature importance score = total weighted impurity reduction caused by that feature.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Result: The tree automatically gives very low importance to “City”. You can safely remove it without
losing much accuracy.
Advantages
Disadvantages
Revision Table
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Definition:
Feature Value
Age 25
Salary 50,000
Problem:
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
1. Avoid Bias
2. Faster Training
3. Better Accuracy
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Example:
• Age: 20 → 0.2
• Age: 50 → 0.8
Xchanged = X - μ / σ
Where:
• μ = mean
• σ = standard deviation
• Age: 20–60
• Salary: 10,000–1,00,000
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
After:
A feature like “salary” (in thousands) can dominate “age” (0–100) in distance-based
algorithms (KNN, SVM) or gradient descent (Neural Networks).
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
After Normalization:
Area becomes 0 to 1,
After Standardization:
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Feature Extraction is the process of creating a new set of features by transforming the original
high-dimensional data into a lower-dimensional space while keeping the most important
information.
Simple Meaning:
Instead of using 100 original features, we create 5–10 new combined features that capture almost
the same information.
• Solves Curse of Dimensionality (too many features → model becomes slow, overfits, and
performance drops).
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Uses
Technique Type Goal Best Used When
Labels?
Definition
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
PCA is an unsupervised technique that finds new axes (principal components) along which the data
has maximum variance.
[Variance measures how much data values spread out from the mean (average).]
PCA Steps
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Mathematical Formula
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Example: House price dataset with 50 features (area, location, age, etc.) → PCA creates 3 new
components that explain 95% variance.
Dataset
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
1 80 85
2 90 88
3 60 65
4 70 72
5 85 90
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
1 0.249 0.457
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
2 1.079 0.731
3 -1.413 -1.372
4 -0.581 -0.731
5 0.665 0.915
1 0.249 0.457
2 1.080 0.732
3 -1.412 -1.372
4 -0.581 -0.732
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
5 0.664 0.915
Calculations
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Definition
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
LDA is a supervised technique that finds new axes that maximize separation between classes
while minimizing variation inside each class.
Key Idea
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
EXAMPLE:
Predicting Student Pass/Fail (Unit III / Unit V – TLO 3.3 & 5.4)
Dataset
1 65 70 Fail (0)
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
2 72 68 Fail (0)
3 60 62 Fail (0)
4 85 88 Pass (1)
5 90 92 Pass (1)
6 78 82 Pass (1)
Goal: Find 1 new axis (LD1) that best separates Pass and Fail students.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
SB shows how far apart the two class means are. High values indicate good separation between Fail and
Pass groups.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Projection Formula
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Result: Reduced 2 exam scores → 1 new score (LD1) with perfect separation between Pass and
Fail.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Pro Tip
Mutual Information (MI) is a Filter Method of feature selection that measures how much
information one feature contains about the target variable (or another feature).
Simple Meaning:
Unlike correlation (which only captures linear relationships), MI captures both linear and non-
linear relationships.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Where:
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Dataset has features: Area, Location, Age, Owner Name, House ID.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Advantages Disadvantages
Works with mixed data types Does not consider feature interactions directly
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
ANOVA (Analysis of Variance) is a statistical method used to compare the means of a numerical
(continuous) feature across two or more groups defined by a categorical target variable (classes in
classification problems).
In feature selection, ANOVA acts as a univariate filter method. It ranks numerical features based
on how well they discriminate between different classes of the target. Features whose means differ
significantly across classes are considered more important.
The goal is to test whether the observed differences in feature values across classes are due to real
group differences (signal) or just random variation (noise).
• If a feature has very different means across classes → it helps separate the classes → high
importance.
• If the means are similar across classes → the feature does not help much in distinguishing
classes → low importance.
ANOVA achieves this by partitioning the total variance of the feature into two parts:
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Where:
Interpretation:
• High F-value → Between-group variance >> Within-group variance → Strong evidence that
class means differ → Feature is highly relevant.
• F-value close to 1 → Between-group variance ≈ Within-group variance → No significant
difference across classes → Feature is less useful or irrelevant.
Along with the F-statistic, ANOVA also provides a p-value. A very small p-value (typically < 0.05)
indicates that the observed difference is statistically significant (unlikely due to chance).
In feature selection, we usually rank features by descending F-score (or ascending p-value) and
select the top-k features.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Between-group sum of squares (SSB) measures how far class means are from the grand mean.
Within-group sum of squares (SSW) measures spread around each class mean.
The F-statistic follows an F-distribution under the null hypothesis (all class means are equal).
For regression problems (continuous target), the equivalent is f_regression (which tests linear
correlation).
Violations (especially of equal variance or normality in small samples) can make the F-test
unreliable.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
• Assumption sensitivity: Performs poorly if data is heavily skewed, has many outliers, or
violates normality/homogeneity.
• Only linear relationships: Misses complex non-linear dependencies between feature and
target.
• Univariate: Ignores interactions between features (does not consider redundancy or
synergy among multiple features).
• Sensitive to outliers, which can inflate variances.
• In very high-dimensional settings, multiple testing issues can arise (though rarely corrected
in basic feature selection).
Because of these limitations, ANOVA is often used as a quick first step and is sometimes
combined with other methods (e.g., mutual information for non-linear cases or wrapper methods
for better performance).
• Similar to Fisher’s discriminant ratio: The F-statistic is closely related to the ratio of
between-class to within-class variance used in linear discriminant analysis.
• Vs. Mutual Information: ANOVA captures linear mean differences; mutual information
captures any type of dependency (including non-linear).
• Vs. t-test: ANOVA generalizes the two-sample t-test to more than two groups.
----------------------------------------------------------------------------------------------------------------------------
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
RFE is model-dependent — the quality of selection depends heavily on the estimator used (e.g.,
Logistic Regression, SVM, Random Forest, etc.).
Plain RFE requires you to manually specify how many features to keep (n_features_to_select).
Choosing this number is tricky and can lead to overfitting or underfitting.
RFECV solves this by integrating k-fold cross-validation to automatically determine the best
number of features.
1. Outer Process: RFECV considers different possible subset sizes (from all features down to
min_features_to_select, usually 1).
2. For each possible number of features (say, from n down to 1):
a. Perform k-fold cross-validation.
b. In each fold:
i. On the training portion of the fold: Run the full RFE process (train estimator →
rank features → recursively eliminate least important ones) until reaching the
current target subset size.
ii. Evaluate the model's performance (using the chosen scoring metric, e.g.,
accuracy, F1, ROC-AUC) on the validation portion of the fold.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
c. Average the performance scores across all k folds for that subset size.
3. Select the optimal number: Choose the number of features that gives the highest average
cross-validated score.
4. Final Model: Once the optimal number is found, RFECV fits a final RFE on the entire
dataset using that optimal number and produces:
a. support_: Boolean mask of selected features.
b. ranking_: Ranking of all features (1 = selected, higher = eliminated earlier).
c. cv_results_: Detailed scores for each subset size.
This makes RFECV more robust and less prone to selecting a suboptimal number of features
compared to plain RFE.
Advantages of RFECV
• Computationally expensive: It runs RFE multiple times (once per fold per subset size). For
large datasets or many features, it can be very slow.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
• Still greedy and univariate in spirit: Although it uses a model, it eliminates features one-
by-one without considering complex interactions in every step.
• Depends heavily on the estimator: A weak or biased estimator can lead to poor feature
ranking.
• May produce different results across different CV folds or random states because of
variability in feature importance.
• Not ideal for extremely high-dimensional data (thousands of features) without sufficient
computational resources.
Manual Automatically
Optimal # features Manual or separate tuning
specification selected
Captures
Partially (via model) Partially (via model) No (univariate)
interactions
RFECV is generally more reliable than plain RFE but slower than univariate filter methods like
ANOVA F-test or Mutual Information.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
RFECV is a classic wrapper method that balances performance and robustness through cross-
validation, making it one of the most widely used techniques for automatic feature selection in
practice.
-----------------------------------------------------------------------------------------------------------------------------
Tree-based models (ensemble methods) provide a built-in mechanism to measure how much
each feature contributes to the model's predictions. This is one of the most popular and effective
ways to perform embedded feature selection.
Unlike filter methods (e.g., ANOVA), tree-based importance is model-dependent — it reflects how
useful the features were during actual model training.
The most common method is Mean Decrease in Impurity (MDI), also called Gini Importance or
Information Gain Importance.
Mechanism:
• Every time a feature is used to split a node in a tree, the impurity (Gini, Entropy, or variance
for regression) decreases.
• The weighted decrease in impurity is attributed to that feature.
• This decrease is averaged across all splits where the feature was used, and across all trees
in the ensemble.
• Features that cause larger, more frequent impurity reductions get higher importance
scores.
The importance is usually normalized so that all feature importances sum to 1 (or 100%).
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
In ensembles (Random Forest, XGBoost, etc.), this is averaged over all trees.
Feature Importance
Model Key Characteristics Best For Limitations
Method
High-
Even more
Extra Trees MDI (similar to RF) dimensional Similar bias
randomization, faster
data
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Gradient
Based on split gain High Can be unstable
Boosting MDI (gain)
during boosting performance in small data
(GBM)
Multiple types
'gain', 'weight', 'cover', Speed + Default 'gain' is
XGBoost available
'total_gain' Performance most common
(importance_type)
'split' (number of times Very fast, leaf-wise Large-scale 'split' can favor
LightGBM
used), 'gain' growth data high-cardinality
Datasets
Built-in importance Handles categorical Slightly different
CatBoost with
(PredictionValuesChange) features natively interpretation
categoricals
1. Gain (most commonly used): Total improvement in loss/impurity from splits using this
feature.
2. Weight / Split: Number of times the feature was used to split.
3. Cover: Number of samples affected by splits on this feature.
4. Total Gain: Sum of gain across all trees.
Gain is generally preferred because it measures actual contribution to model quality, not just
frequency of use.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
• Bias towards high-cardinality features: Features with many unique values (e.g., IDs,
continuous features with high precision) tend to get inflated importance.
• Not reliable for correlated features: When two features are highly correlated, importance
can be arbitrarily split between them.
• Can be misleading on small datasets or with noisy data.
• Does not consider feature removal effect directly (unlike RFE).
• Permutation importance is often recommended as a more robust alternative (see below).
-----------------------------------------------------------------------------------------------------------------------------
XGBoost Feature Importance
XGBoost (eXtreme Gradient Boosting) is one of the most powerful tree-based ensemble models. It
builds trees sequentially (boosting), where each new tree corrects the errors of the previous ones.
This sequential nature, combined with regularization and optimized splitting, makes its feature
importance scores particularly insightful.
XGBoost calculates feature importance by analyzing how much each feature contributes during
the tree-building process across all boosting rounds (trees).
The core mechanism is similar to other tree-based models (impurity reduction or split gain), but
XGBoost provides multiple distinct ways to quantify importance. These are accessible via
get_score(importance_type=...) in the Booster API or feature_importances_ in the scikit-
learn wrapper (default is usually 'gain').
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Key Insight:
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
• Gain / Total_Gain → Focus on quality of contribution (how much the model improves).
• Weight → Focus on frequency of usage.
• Cover → Focus on breadth of influence on samples.
In practice, Gain is widely preferred because it better captures the true discriminative power of a
feature, especially in classification and regression tasks.
• Bias toward high-cardinality features: Features with many distinct values (e.g.,
continuous variables or high-cardinality categoricals) tend to get higher weight/cover scores
because they allow more possible split points.
• Correlated features: Importance can be arbitrarily distributed among highly correlated
features.
• Depends on hyperparameters: Changing max_depth, min_child_weight, number of
trees, or subsample can alter importance rankings.
• Not fully model-agnostic: It explains the trained XGBoost model, not necessarily the
underlying data relationships.
• Can be unstable on small or noisy datasets.
Because of these issues, many practitioners cross-validate importance rankings or combine with
permutation importance or SHAP values for more robust interpretation.
• Similar Foundation: Both use impurity reduction / split gain averaged across trees.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
• Key Difference:
o Random Forest: Bagging (parallel trees, averaging predictions) → more stable
importance.
o XGBoost: Boosting (sequential trees, focusing on residuals) + regularization →
importance can be more sensitive to the error-correcting process.
• XGBoost often gives sharper distinction on truly important features due to its focus on hard
examples.
• Random Forest importance tends to be smoother and less prone to extreme shifts.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
-----------------------------------------------------------------------------------------------------------------------------
LightGBM Feature Importance
LightGBM (Light Gradient Boosting Machine) is a highly efficient gradient boosting framework
developed by Microsoft. It is designed for speed and scalability on large datasets, using leaf-wise
tree growth (instead of level-wise like XGBoost), histogram-based splitting, Gradient-based One-
Side Sampling (GOSS), and Exclusive Feature Bundling (EFB).
Despite these optimizations, its feature importance mechanism remains rooted in the same tree-
based impurity reduction principles as other boosting algorithms.
LightGBM provides two primary types of feature importance (controlled by the importance_type
parameter):
1. Split (Default)
a. Counts the number of times a feature is used to make a split across all trees in the
ensemble.
b. It is a frequency-based measure.
c. Higher value = the feature was selected more often for splitting.
d. Pros: Simple, fast to compute, gives a good sense of how "active" a feature is.
e. Cons: Biased toward features with high cardinality (many possible split points) or
features that appear in shallow splits. It does not measure the quality of the splits.
2. Gain
a. Measures the total improvement (reduction in loss or impurity) achieved by splits
that use this feature across all trees.
b. It sums up the gain (decrease in the objective function) from every split made on
that feature.
c. Higher gain = the feature contributes more to improving the model's accuracy/loss
reduction.
d. Pros: More informative and better reflects the actual predictive contribution of the
feature.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
e. Cons: Values can be very large and skewed; harder to interpret in absolute terms.
Key Recommendation:
Use Gain for most interpretability and feature selection tasks because it focuses on the quality and
impact of splits rather than mere frequency.
• During training, every split evaluates potential features using histogram approximations for
speed.
• For each valid split, LightGBM computes the gain — the reduction in the loss function (e.g.,
log loss for classification, MSE for regression).
• Split importance simply increments a counter each time the feature is chosen.
• Gain importance accumulates the actual gain value from those splits.
• The final importance is aggregated over all boosting iterations (trees).
This process is closely tied to LightGBM’s leaf-wise growth strategy: trees grow by always splitting
the leaf with the largest loss reduction, which can lead to deeper, more complex trees and
potentially sharper importance distinctions.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Growth Strategy Leaf-wise → can favor features that allow big Level-wise → more balanced
Impact loss reductions splits
Speed &
Extremely fast even on large data Slightly slower
Scalability
Differences: LightGBM’s leaf-wise growth and histogram approximations can sometimes produce
more aggressive splits, making Gain importance even more critical to examine (as frequency alone
may mislead).
• Split importance is biased toward features with more possible split points (high cardinality
or continuous features).
• Gain can produce extremely large or skewed values, especially with more trees.
• Correlated features: Importance gets split arbitrarily between them.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
For robust analysis, many practitioners combine LightGBM importance with permutation
importance or SHAP values.
• Train the model → extract Gain or Split scores → select top-k features or apply a threshold.
• Often used inside RFECV (with LGBMClassifier as estimator).
• Good first step before more expensive wrapper methods.
• Helps reduce dimensionality quickly on large feature sets.
--------------------------------------------------------------------------------------------------------------
This is the default and true built-in feature importance in Random Forest.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
• Each decision tree in the forest uses Gini impurity (for classification) or variance reduction
(for regression) as the splitting criterion.
• When a feature is chosen for a split at a node, it reduces the impurity (or variance) of that
node.
• The decrease in impurity caused by the split is attributed to that feature.
• This decrease is weighted by the number of samples reaching that node.
• For the entire forest:
o The impurity decrease for a feature is averaged across all trees.
o The result is normalized so that the sum of all feature importances equals 1.
Mathematical Intuition:
In Random Forest, this is averaged over all trees → Mean Decrease in Impurity (MDI), commonly
called Gini Importance.
Advantages:
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Important Clarification:
SHAP values assign a value to each feature for every individual prediction, representing how
much that feature pushes the prediction away from the base (average) prediction.
• They satisfy local accuracy, missingness, and consistency properties (from Shapley
values).
• Global feature importance from SHAP is usually the mean absolute SHAP value across
all samples.
Post-hoc explanation
Type Built-in to Random Forest
(TreeExplainer)
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
• Gini/MDI importance can be misleading due to bias toward features with many unique
values (high cardinality).
• It is calculated on training data, so it may inflate importance of features that help overfit.
• SHAP provides more faithful explanations aligned with actual contribution to predictions.
===============================================================================
===============================================================================
===============================================================================
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Supervised Learning
1. What is Supervised Learning?
Supervised Learning is a type of Machine Learning where the algorithm learns from
labeled data.
In simple words:
→ We give the model both input (features) and correct output (label/target) during
training.
→ After training, it can predict the output for new, unseen data.
Key Point:
The word “Supervised” means the learning process is guided/supervised by the correct
answers (labels) provided in the training data.
House Price Prediction Area, location, no. of rooms, age Price (in ₹) Regression
Spam or Not
Email Spam Detection Email text, sender, subject Classification
Spam
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Has Disease or
Medical Diagnosis Blood pressure, sugar level, age Classification
Not
A. Classification
B. Regression
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
1. Decision Tree
Definition:
A Decision Tree is a tree-like structure where each internal node represents a test on a
feature; each branch represents the outcome of the test, and each leaf node represents
the final prediction.
How it Works:
• It recursively splits the data into subsets based on the most informative feature.
• Splitting criteria: Gini Impurity or Information Gain (Entropy).
• Continues until pure nodes or stopping conditions are met.
Example:
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Definition:
KNN is a lazy, instance-based learning algorithm that classifies a new data point based on
the majority class of its K nearest neighbors.
How it Works:
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Example:
Look at 5 most similar patients → 4 had “Flu”, 1 had “Cold” → Predict Flu.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Disadvantages: Slow for large data, very sensitive to scaling and irrelevant features.
Definition
SVM is a supervised classification algorithm that finds the hyperplane (decision boundary) that best
separates the classes with the maximum margin.
Simple Meaning
It draws the widest possible “street” between two classes so that the boundary is as far as possible from
the nearest data points (called support vectors).
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
• Maximizes the margin (gap) between the hyperplane and support vectors.
• For non-linear data → uses Kernel Trick (maps data to higher dimension).
Common Kernels
• Linear
• Polynomial
• RBF (Radial Basis Function) – most popular
Visual Example
Real-Life Example
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
SVM draws a boundary that keeps maximum gap between spam and non-spam points.
Advantages
Disadvantages
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
2. Regression Algorithms
A. Linear Regression
Equation:
Y = mx + c
Where,
How it Works: Minimizes the sum of squared errors (best fit line).
Example: Predict house price based on area ([Link]). As area increases, price increases
linearly.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
B. Logistic Regression
Definition: Used for binary classification (output 0 or 1). It is called “regression” but used
for classification.
How it Works:
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
• Sigmoid:
Calculation:
Definition
Meaning of Terms
Term Meaning
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Role of z
3. Convert z → probability (0 to 1)
📊 Example
Suppose:
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Understanding
• z = weighted sum of inputs
• It is the input to sigmoid function
• It decides final probability
Example: Predict whether a student will Pass or Fail based on study hours.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Ridge Regression is a type of Linear Regression with L2 regularization (penalty on the square of
coefficients).
It is used to prevent overfitting and handle multicollinearity (when features are highly correlated).
NOTE:
Overfitting is a situation in machine learning where a model learns the training data too well, including
noise and unnecessary details, and performs poorly on new (unseen) data.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Multicollinearity
Multicollinearity occurs when two or more independent variables (features) in a dataset are highly
correlated with each other.
Problem
Simple Meaning
Normal Linear Regression can make very large coefficients → unstable model.
Ridge adds a small penalty on large coefficients so the model becomes simpler and more stable.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Mathematical Formulation
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Real-Life Example
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Advantages Disadvantages
Computationally efficient —
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Key Metrics:
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Majority vote of K
KNN Classification Category Flower classification
neighbors
House price
Linear Regression Regression Continuous Best fit straight line
prediction
Logistic
Classification Probability Sigmoid function Pass/Fail prediction
Regression
After training a model (especially in Supervised Learning), we must check how well it is performing on
unseen test data.
This is done using a Confusion Matrix + key metrics: Accuracy, Precision, and Recall.
These metrics are mainly used for Classification problems (e.g., Spam/Not-Spam, Pass/Fail, Disease/No-
Disease).
1. Confusion Matrix
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Pro Tip:
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
=====================================================================================
=====================================================================================
=====================================================================================
Unsupervised Learning
1. What is Unsupervised Learning?
Unsupervised Learning is a type of Machine Learning where the algorithm learns from
unlabelled data.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
• Supervised Learning → Data has labels (e.g., Pass/Fail, Price, Spam/Not Spam)
• Unsupervised Learning → Data has no labels
1 25 45,000 65
2 32 78,000 82
3 45 32,000 25
4 28 65,000 78
5 50 1,20,000 15
• Young high-spenders
• Middle-aged low-spenders
• Old premium customers
This is the power of Unsupervised Learning — it finds hidden patterns without any
guidance.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
3. Clustering Techniques
What is Clustering?
Clustering is the task of dividing unlabelled data into groups (clusters) such that data
points in the same cluster are more similar to each other than to those in other clusters.
A. K-Means Clustering
Steps:
• Cluster 1: Young customers with high spending (Age ~25–30, Spending >70)
• Cluster 2: Middle-aged moderate spenders
• Cluster 3: Older customers with low spending
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
B. Hierarchical Clustering
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
There are two primary types of hierarchical clustering based on the direction of hierarchy
construction:
• Starting Point: Each data point begins as its own singleton cluster (N clusters for N
data points).
• Process: Iteratively merge the two most similar (closest) clusters into a larger
cluster.
• Ending Point: Continue merging until all points form a single cluster (or until a
stopping criterion is met).
• Direction: Bottom → Up (small clusters → larger clusters).
Advantages:
• Simple to implement.
• Computationally more efficient for small to medium datasets.
• Produces a natural hierarchy.
Disadvantages:
• Once two clusters are merged, they cannot be separated later (greedy nature — no
backtracking).
• Can be sensitive to noise/outliers depending on the linkage method.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
• Starting Point: All data points start in one single large cluster.
• Process: Recursively split the largest (or most heterogeneous) cluster into smaller
sub-clusters.
• Ending Point: Continue splitting until each data point becomes its own singleton
cluster.
• Direction: Top → Down (large cluster → small clusters).
Advantages:
Disadvantages:
• Computationally much more expensive (requires deciding how and where to split
at each step, often involving combinatorial choices).
• More complex to implement.
• Less popular due to higher time complexity.
Comparison Table:
Starting Point Each point = own cluster All points in one cluster
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
In practice, agglomerative clustering is almost always preferred due to its efficiency and
ease.
Limitations (Overall)
• Scalability: O(N²) time and space complexity — not suitable for very large datasets
(millions of points).
• Irreversibility: Once merged/split, decisions cannot be undone.
• Sensitive to noise and outliers (especially single linkage).
• Choice of linkage and distance metric significantly impacts results.
The dendrogram may show that at height = 10, there are 3 natural groups of customers —
same as K-Means but with hierarchy.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Dimensionality Reduction is the process of reducing the number of input features (dimensions) while
preserving as much useful information as possible.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
1. Curse of Dimensionality
a. In high dimensions, data becomes sparse → distance between points becomes
meaningless.
b. Models overfit easily and performance drops.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
2. Computational Efficiency
a. Fewer features = faster training and lower memory usage.
3. Overfitting Prevention
a. Removes noise and redundant features → better generalization on new data.
4. Improved Visualization
a. High-dimensional data (50+ features) cannot be plotted → reduce to 2D/3D for easy
understanding.
5. Better Model Performance
a. Removes irrelevant features → higher accuracy and faster convergence.
Real-Life Example
House price dataset with 100 features → after dimensionality reduction → only 10–15 important
components → model trains 10x faster with same or better accuracy.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Definition
PCA is an unsupervised dimensionality reduction technique that transforms original features into a new
set of uncorrelated features (Principal Components) while maximizing variance (information retained).
Fundamental Principles
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Let’s break down Eigenvalues and Eigenvectors in a clear, student-friendly way (very important for PCA
in your syllabus).
These special vectors are called Eigenvectors, and the amount of stretching/shrinking is called the
Eigenvalue.
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
🔹 Mathematical Definition
Intuition
Think of it like:
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Step-by-Step Example
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Key Points
Steps in PCA
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Advantages Disadvantages
Applications of PCA
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204
by Kunal Sir
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052 , Mobile No.- 8888022204