2.5.4 · HinglishUnsupervised Learning

Hierarchical clustering (agglomerative - divisive)

3,242 words15 min readRead in English

2.5.4 · AI-ML › Unsupervised Learning

Hierarchical Clustering Kya Hai?

Ye Kyun Zaroori Hai

Woh problem jo K-Means poorly solve karta hai: Tumhare paas customer data hai lekin tum nahi jaante ki 3, 5, ya 10 groups mein segment karna chahiye. K-Means tumhe K guess karne par majboor karta hai, phir galat hone par dobara start karna padta hai.

Hierarchical solution: Poora tree EK BAAR banao, phir natural number of clusters choose karne ke liye use examine karo. Tree tumhe dikhata hai ki BDE separations KAHAN hote hain.

Do Approaches

1. Agglomerative Clustering (Bottom-Up)

Complexity ki Derivation:

  • points, iteration mein clusters hain
  • Saare pairwise distances compute karna: comparisons
  • Total: naive implementation ke liye
  • Priority queue (heap) ke saath:

2. Divisive Clustering (Top-Down)

Linkage Criteria (Agglomerative ka Dil)

Linkage criterion define karta hai "clusters ke beech distance". Ye choice drastically cluster shapes change kar deta hai.

Ward's Formula ki Derivation:

Merged cluster ke liye within-cluster sum of squares:

jahan

Expanding:

Parallel axis theorem use karke:

Algebra ke baad:

Ye kyun matter karta hai: Ward's merging se total within-cluster variance mein INCREASE minimize karta hai, compact, roughly equal-sized clusters produce karta hai.

Dendrogram: Tree Padhna

Number of clusters kaise choose karein:

  1. Bade vertical gaps dekho (merge distance mein bada increase)
  2. Bade jump se thoda pehle cut karo
  3. Jitni vertical lines tum cut karte ho = utne clusters

Implementation Details

Distance Metric (usually Euclidean):

High-dimensional data ke liye, consider karo:

  • Manhattan: (outliers ke liye robust)
  • Cosine: (angle-based, text ke liye achha)

Update Formula (Lance-Williams): Clusters aur ko mein merge karne ke baad, baaki cluster ke distances update karo:

Different linkages ke liye parameters:

  • Single: (do distances ka min)
  • Complete: (do distances ka max)
  • Average:

Advantages & Disadvantages

Advantages:

  1. K pehle se specify karne ki zaroorat nahi — ek tree se multiple granularities explore karo
  2. Interpretable output — dendrogram cluster relationships aur hierarchy dikhata hai
  3. Deterministic — same data hamesha same tree deta hai (K-Means ke random init ke unlike)
  4. Kisi bhi distance metric ke saath kaam karta hai — Euclidean space tak limited nahi

Disadvantages:

  1. Computational cost: time, space (distance matrix)
    • K-Means hai jahan = iterations, usually bahut faster
  2. Greedy aur irreversible — early merge mistakes ko undo nahi kiya ja sakta
  3. Outliers ke liye sensitive (especially single linkage)
  4. Scalable nahi — approximations ke bina points ke liye impractical

Hierarchical kab use karein:

  • Small-to-medium datasets ()
  • Sirf flat partition nahi, cluster hierarchy chahiye
  • Natural K determine karne ke liye exploratory analysis
  • Biological taxonomy, document hierarchies (true hierarchical structure)

Kab avoid karein:

  • Large datasets (K-Means, DBSCAN, ya mini-batch variants use karo)
  • Complex shapes wale clusters (DBSCAN use karo)
  • Naya data aane par clusters update karne ki zaroorat ho (hierarchical mein full rebuild chahiye)
Recall 12-saal ke bachche ko explain karo

Socho tumhare paas zameen par bahut saare LEGO bricks bikre hue hain, alag-alag colors aur sizes ke. Hierarchical clustering unhe groups mein organize karne jaisa hai.

Agglomerative (bottom-up): Tum har brick uthana shuru karte ho. Phir tum do MOST similar bricks dhundhte ho (shayad dono red, ya dono 2x4 size) aur unhe saath rakh dete ho. Phir tum ye karte rehte ho: do groups dhundho jo sabse zyada similar hain aur combine karo. Shayad tum do red piles combine karo, ya ek red pile ko ek pink pile ke saath (woh kinda similar hain!). Eventually, tumhare saare bricks ek giant pile mein aa jaate hain.

Cool part? Tumne poora time video liya. Ab tum kisi bhi point par rewind aur stop kar sakte ho alag groupings dekhne ke liye. Shayad tum 3 piles chahte ho (primary colors), ya 10 piles (har shade), ya 100 piles (almost har brick alag). Jab tak video na dekho choose nahi karna padta!

Divisive (top-down): Ye ulta karna jaisa hai. Ek pile mein saare bricks se shuru karo, phir use do groups mein split karo (shayad "red-ish" vs "blue-ish"). Phir un dono groups mein se har ek ko dobara split karo, aur baar baar, jab tak har brick akela na ho jaye.

"Dendrogram" tumhare LEGO bricks ka family tree jaisa hai, jo dikhata hai ki kaun se bricks "related" (similar) hain aur kaun se "distant cousins" hain (bahut different). Har branch ki height dikhati hai ki jab tum unhe combine kar rahe the tab groups KITNE different the.

Connections

  • K-Means Clustering — flat clustering jo K upfront maangta hai; hierarchical K choose karne mein help karta hai
  • DBSCAN — density-based alternative; non-convex clusters ke liye better, hierarchical interpretability ke liye better
  • Distance Metrics — Euclidean, Manhattan, Cosine ka choice drastically clustering affect karta hai
  • Dendrogram Visualization — cluster hierarchy ki tree representation
  • Elbow Method — optimal K determine karne ke liye use hota hai; dendrogram merge heights par apply hota hai
  • Single-Link vs Complete-Link — chaining vs outliers ke sensitivity ke beech trade-off
  • Time Complexity Analysis naive, optimized vs K-Means
  • Greedy Algorithms — hierarchical greedy merging use karta hai, globally optimal nahi
  • Within-Cluster Sum of Squares — Ward's method WCSS increase minimize karta hai

#flashcards/ai-ml

Hierarchical clustering ke do main types kya hain? :: Agglomerative (bottom-up merging) aur Divisive (top-down splitting)

Hierarchical clustering ka output kya hota hai?
Ek dendrogram (tree structure) jo saare levels of granularity par cluster relationships dikhata hai, sirf ek single partition nahi
Priority queue ke saath agglomerative clustering ki time complexity kya hai?
time aur space distance matrix ke liye
Single linkage criterion kya hai?
Clusters ke beech distance = do clusters ke kisi bhi do points ke beech minimum distance:
Complete linkage criterion kya hai?
Clusters ke beech distance = do clusters ke kisi bhi do points ke beech maximum distance:
Ward's linkage criterion kya hai?
Woh clusters merge karo jo total within-cluster variance mein increase minimize karein:
Single linkage mein chaining effect kya hota hai?
Single linkage clusters ko outlier bridges ya noise points ke through connect karta hai, compact clusters ki jagah elongated chains banata hai
Dendrogram se clusters ki number kaise choose karein?
Bade vertical gaps (merge height mein bade jumps) dekho aur dendrogram ko horizontally bade jump se thoda pehle cut karo
K-Means ke muqable hierarchical clustering ka main advantage kya hai?
K upfront specify karne ki zaroorat nahi — tumhe saari granularities par cluster structure milta hai aur tum dendrogram examine karke K choose kar sakte ho
Hierarchical clustering globally optimal kyun nahi hai?
Ye har merge step par greedy local decisions use karta hai. Ek baar do clusters merge ho jaayein toh kabhi split nahi hote, isliye early mistakes propagate ho jaati hain
Complete linkage single linkage ke upar kab use karein?
Complete linkage tab use karo jab compact, well-separated clusters chahiye aur data mein noise ya outliers hon. Single linkage in cases mein chaining se suffer karta hai
Large datasets ke liye hierarchical clustering ka main disadvantage kya hai?
Distance matrix ke liye space aur time use karne ki wajah se points ke liye impractical ho jaata hai
Dendrogram mein merge ki height kya represent karti hai?
Us step par merge ho rahe do clusters ke beech distance ya dissimilarity
Average linkage single aur complete linkage se kaise different hai?
Average linkage clusters ke beech saare pairwise distances ka mean use karta hai, single (minimum) aur complete (maximum) ke beech ek compromise provide karta hai
Ward's method balanced clusters banane ke liye kyun achha hai?
Ye within-cluster variance increase minimize karta hai, jo naturally similar size aur low internal variance wale compact clusters produce karta hai

Concept Map

builds

bottom-up

top-down

uses

repeatedly

records

repeatedly

uses

records

big jump marks

choose K by

naive cost

Hierarchical Clustering

Dendrogram Tree

Agglomerative AGNES

Divisive DIANA

Linkage Criterion L

Merge Nearest Clusters

Split Largest Cluster

Merge/Split Height

K-Means Split K=2

Cut Tree Later

Complexity O n cubed