Day 28 of 133

ML coding from scratch — k-means, kNN, logistic regression

Implement, time, debug. The most-skipped form of practice.

DSA · NeetCode Heap / Priority Queue

  • Kth Largest Element IN A StreamDSA · Heap / Priority Queue

    Interview questions to prep

    1. Why is a heap the right structure? Could a balanced BST or sorted list work — why is heap better?
    2. Explain the heap-of-k pattern: keep size k, push new, pop if over k. What's the resulting complexity?
    3. What does the comparator look like, and how would you tweak it to flip min/max behaviour?
  • Last Stone WeightDSA · Heap / Priority Queue

    Interview questions to prep

    1. Why is a heap the right structure? Could a balanced BST or sorted list work — why is heap better?
    2. Explain the heap-of-k pattern: keep size k, push new, pop if over k. What's the resulting complexity?
    3. What does the comparator look like, and how would you tweak it to flip min/max behaviour?

ML · Coding from scratch

  • Code k-NN classifier from scratchTraditional MLalirezadir

    Interview questions to prep

    1. Implement k-NN from scratch and explain its time/space complexity.
    2. How would you speed up k-NN inference on millions of points without changing the prediction?
  • Code k-means from scratchTraditional MLalirezadir

    Interview questions to prep

    1. Implement k-means with k-means++ initialization.
    2. Why does k-means++ initialization matter, and what does it cost vs random init?
  • Code logistic regression with SGDTraditional MLalirezadir

    Interview questions to prep

    1. Implement logistic regression with mini-batch SGD and L2 regularization.
    2. What numerical-stability pitfalls do you watch out for when implementing the sigmoid + log-loss?
  • Interview questions to prep

    1. Implement linear regression training with vectorized gradients and a learning-rate parameter.
    2. How do you verify your from-scratch implementation against sklearn or a closed-form OLS solution?

References & further reading