Navigate Select ESC Close

K-Means Clustering From Scratch in Python (Mathematical)

2023-06-25 Science & Technology
42.6k
1.1k
27
NeuralNine
NeuralNine
475.0k subscribers

Unlock all features

FREE: Get instant access to 10 AI summaries, chats, or transcripts per day.

Description

In this video we implement K-Means clustering from scratch. We look at the theory and the mathematics behind it and then we use NumPy to put it into code. ◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾ 📚 Programming Books & Merch 📚 🐍 The Python Bible Book: https://www.neuralnine.com/books/ 💻 The Algorithm Bible Book: https://www.neuralnine.com/books/ 👕 Programming Merch: https://www.neuralnine.com/shop 💼 Services 💼 💻 Freelancing & Tutoring: https://www.neuralnine.com/services 🌐 Social Media & Contact 🌐 📱 Website: https://www.neuralnine.com/ 📷 Instagram: https://www.instagram.com/neuralnine 🐦 Twitter: https://twitter.com/neuralnine 🤵 LinkedIn: https://www.linkedin.com/company/neuralnine/ 📁 GitHub: https://github.com/NeuralNine 🎙 Discord: https://discord.gg/JU4xr8U3dm Timestamps: (0:00) Intro (0:17) Theory & Math Background (7:21) Coding K-Means From Scratch (32:37) Outro

Top Comments (10)

@pitaeata8493 2023-07-03

this is great, thank you. it feels good to understand something and be a little closer to understanding machine learning or how to use it properly.

14
@martxrrr 2025-11-26

Slowly becoming a Machine Learning Engineer through the knowledge shared by NeuralNine. Thank you G❤

1
@linusolmin9313 2024-06-02

Thank you very much!

0
@arnaldocosta3233 2024-09-23

Thanks!

0
@Hickssama 2024-03-17

Thank you sir

0
@rezaaminafshar 2024-08-18

Hi, thanks for your comprehensive explanation. I want to use cosine distance as metric instead of Euclidean distance. could you please guide me? shoud we just change the part of code which calcaulates Euclidean distance or also other changes need?

0
@nox8208 2025-09-30

Thanks for the great video! Regarding the centroid initialization, could it be that you’re encountering an issue with the range of values for the wrong axis? For instance, if the x-axis has a range of [-3: 3] and the y-axis has a range of [-1000: 1000], a centroid could potentially end up with coordinates like [-800, 200]. Is that correct, or did I miss something?

0
@tcgvsocg1458 2023-06-26

really interesting

0
@SeziManuhutu 2024-02-21

your explanation is great. but i want to ask, what if we want to know what data is move to different cluster. like at first the data is in 0 cluster but then after that it's move to the other group. how do we know the number of data that is move to another cluster?

0
@medmigalexandernaslund 2023-10-11

I'm glad I found this tutorial!

0

Unlock the Data Inside
Turn Videos into Knowledge

  • Get FREE 10/day: transcripts, summaries, chats
  • Chat with videos, export text & PDF
  • $1 free API credit for RAG, chatbots & research

Free forever plan • All features unlocked

App screenshot