PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Tubitv

Implement K-Means and compare with GMM

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding and practical implementation of clustering algorithms, specifically K-Means centroid initialization, assignment and update mechanics, convergence criteria and edge-case handling, along with comparative knowledge of Gaussian Mixture Models and the Expectation-Maximization training framework.

  • medium
  • Tubitv
  • Coding & Algorithms
  • Machine Learning Engineer

Implement K-Means and compare with GMM

Company: Tubitv

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Implement K-Means clustering from scratch for a dataset `X` of shape `(n_samples, n_features)` and a target number of clusters `k`. Your implementation should: - initialize `k` centroids, - assign each point to its nearest centroid, - recompute centroids as the mean of assigned points, - repeat until convergence or a maximum number of iterations, - handle edge cases such as empty clusters, - and include a test or check for convergence, such as unchanged assignments, centroid movement below a tolerance, or non-increasing within-cluster loss. After coding, answer these follow-up questions: - How does Gaussian Mixture Modeling differ from K-Means? - How would you train a Gaussian mixture model using the EM algorithm? - In what situations would you prefer GMM over K-Means?

Quick Answer: This question evaluates understanding and practical implementation of clustering algorithms, specifically K-Means centroid initialization, assignment and update mechanics, convergence criteria and edge-case handling, along with comparative knowledge of Gaussian Mixture Models and the Expectation-Maximization training framework.

Related Interview Questions

  • Weighted Random Sampling by Index - Tubitv (medium)
Tubitv logo
Tubitv
Jan 28, 2026, 12:00 AM
Machine Learning Engineer
Technical Screen
Coding & Algorithms
2
0

Implement K-Means clustering from scratch for a dataset X of shape (n_samples, n_features) and a target number of clusters k.

Your implementation should:

  • initialize k centroids,
  • assign each point to its nearest centroid,
  • recompute centroids as the mean of assigned points,
  • repeat until convergence or a maximum number of iterations,
  • handle edge cases such as empty clusters,
  • and include a test or check for convergence, such as unchanged assignments, centroid movement below a tolerance, or non-increasing within-cluster loss.

After coding, answer these follow-up questions:

  • How does Gaussian Mixture Modeling differ from K-Means?
  • How would you train a Gaussian mixture model using the EM algorithm?
  • In what situations would you prefer GMM over K-Means?

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Tubitv•More Machine Learning Engineer•Tubitv Machine Learning Engineer•Tubitv Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.