Skip to content
المشاريع

di37/animated-machine-learning-algorithm

عرض على GitHub

حول

Watch scikit-learn models learn and predict: live training and inference animations, narrated lessons and Manim videos for California Housing (regression) and Titanic (classification)

التعلّم والتعليم

كيف تُقاس هذه الأرقام

31 نجمة0 التفرعات +1 خلال 24 ساعة

النمو المقاس للنجوم

خلال 24 ساعة
+١
خلال 7 أيام
+٢
خلال 15 يومًا
جارٍ جمع السجل
خلال شهر
جارٍ جمع السجل

تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.

README.md

الأصل

🎬 Machine Learning Algorithms, Animated

Stop staring at loss curves. Watch the algorithm itself learn,
then watch it explain every prediction it makes.

Watch on the website 91 videos 30 models Python 3.10+ scikit-learn matplotlib and Manim GitHub stars

Four of the 91 videos: a decision tree growing, gradient boosting explaining a Titanic passenger, a narrated lesson's 3-D view, and four models learning who survived

30 models · 3 real datasets · 91 videos · every frame a real model state · every prediction checked ✅

🌐 Watch all 91 videos in your browser on the website →

🔍 The black box, opened. Watch 30 models learn three real datasets, frame by frame, then predict on data they have never seen. You see what each model stores, how it combines its inputs, and exactly why it gave this answer for this example, worked through and checked against the model's own output.

⭐ If an algorithm finally clicks for you here, star the repo and share it with someone learning ML.

Three real datasets, two renderers, 91 videos:

🏠 California Housing 🚢 Titanic 🛒 Wholesale customers
Task regression: a district's median house value classification: who survived clustering: customer segments, with no answer to learn from
Data 20,640 districts, 8 features 1,309 passengers (OpenML titanic) 440 customers, 6 kinds of spending (UCI, CC BY 4.0)
📊 Live dashboards 9 regressors × training + inference 9 classifiers × training + inference none
🏁 Comparison scenes The Algorithm Race · Watch the model learn California The Algorithm Race · Who survives? none
🎓 Narrated lessons 9 lessons, matplotlib + voiced Manim 🔊 9 lessons, matplotlib + voiced Manim 🔊 9 lessons, voiced Manim 🔊
🎞️ Videos 40 40 11

[!TIP] Every picture below is a live loop of the real video, and the lessons play as a 9-second time-lapse. Click any preview, or its ▶️ link, to play the full video in your browser.

🆚 Why this is different from other ML explainers

Most explainers show you an idea of an algorithm. This shows you the algorithm itself, running.

📺 Most ML explainers 🎬 Here
🎨 Hand-animated or idealised curves, drawn to look right 🔁 Every frame is a snapshot of a real scikit-learn model, taken during real training
🧸 Synthetic blobs, generated to behave for the demo 📚 Real records only: 20,640 California census districts, 1,309 Titanic passengers and 440 wholesale customers. The first two are classics you already know, so all your attention goes to the algorithm
🏁 The finished model only 🎞️ A model's whole life: data → first guess → training → final model → inference → test exam
📉 A loss curve and an accuracy number 🔍 The internals themselves: weights, splits, votes, support vectors, bell curves, activations
🪄 "The model says 0.82", taken on trust ✅ The prediction worked out step by step, and checked against the model's own predict before it may show ✓
🧮 After-the-fact approximations of what the model did 🧠 The model's own parameters, read straight from the fitted estimator
🔬 One algorithm at a time, each on its own example ⚖️ Many models on the same data, side by side: races, landscapes, a scoreboard
🤷 Training accuracy, or no score at all 🧪 Train vs validation vs held-out test, no leakage, and statistical tests before any "better"
👀 Watch-only 🛠️ Open source and reproducible: one command regenerates any video, and tests guard every rule

🎁 What you'll get out of it

If you are… You'll walk away with…
🌱 An ML enthusiast or student Intuition that formulas alone don't give: why a deep tree over-fits, why boosting takes many small steps, why KNN "learns" nothing, and what a neural network's weights actually do.
🧑‍💻 A data scientist or ML engineer A sharper eye for model behaviour as it happens: bias and variance in motion, regularisation paths, overconfident scores, and honest evaluation habits (validation for choices, the test set once).
🏢 A lead who explains models to stakeholders Pictures that answer "why did the model say that?" for a single case, with numbers that match the model exactly.
🧑‍🏫 An educator or content creator Ready-made lessons, one algorithm each: 108-second versions that work with the sound off, voiced Manim versions, and the code to make your own.
💼 Someone preparing for interviews A visual memory of 20+ algorithms: how each one trains, how it predicts, and where it breaks.
🛠️ A builder of ML tools A tested pattern for truthful visualisation: immutable snapshots, checked predictions, no invented frames.

🧭 Contents

🔍 Opening the black box

A trained model is usually a black box: numbers go in, a prediction comes out, and you are asked to trust it. These videos open the box. They draw the model's own internals, read straight from the fitted estimator (coef_, tree_, estimators_, support_vectors_, theta_ and var_, coefs_), not an after-the-fact approximation such as a surrogate model or a feature-attribution estimate. That is what makes every explanation checkable: the worked equation is the model's real computation, so it has to land on predict's exact answer before it prints ✓.

Model 🗃️ What is inside the box 🔎 Why it gave this answer
📏 Linear, Ridge, Lasso, SGD every weight, drawn as an edge whose width and colour follow it; Lasso's zeroed features go dashed each feature's push w·x, summed with the bias into the price
📈 Logistic regression, perceptron, linear SVM the same weighted sum, plus the S-curve or the ±1 margin the score z, its side of the threshold, and σ(z) where it is a real probability
🌳 Decision tree every split, with its threshold in real units ("age ≤ 12.5?"), nodes coloured by their examples' average price or survival share the exact path of yes/no questions, and the training examples that share its leaf
🌲 Random forest the individual trees, not just their average every tree's vote, and the average the forest returns
🚀 Gradient boosting each tree's correction, shrinking as the errors shrink the running total from the base rate F₀, tree by tree, to the final answer
📍 k-nearest neighbours the stored training examples, which is all KNN keeps the k nearest examples and their prices or fates
🛡️ SVM (RBF kernel) which training passengers became support vectors, and how much each weighs (α) the strongest pulls α·y·K(xᵢ, x) and the margin f(x) they add up to
🔔 Naive Bayes the base rates and one bell curve per feature and outcome how strongly each feature's value favours "survived" over "did not" (its log-likelihood ratio)
🧠 Neural network (MLP) every weight, re-coloured each epoch as training moves it the forward pass: which hidden units fire and how much signal each edge carries

Seeing the box open teaches things a score never shows:

  • Why linear models plateau: they can only tilt one weighted sum.
  • Why one deep tree over-fits: its leaves shrink to single passengers.
  • Why averaging trees helps: the votes spread out, and their mean is steadier than any one tree.
  • What KNN actually learns: nothing but its memory.

Honest limits:

  • An MLP's hidden units have no human meaning. The diagram shows the computation, not a concept.
  • The KNN and SVM maps squeeze 8 features onto 2 axes (PCA), so "near" on the map is only roughly "near" to the model.
  • A margin model's score (SVM, perceptron) is never called a probability.

👀 How well training and inference are visualised

Most "ML animations" are a loss curve and a confusion matrix. These videos show the algorithm itself working, synchronised with the numbers that prove it, at both stages of a model's life.

🏋️ At training time

  • Every frame is real training work. A frame is drawn the moment the model finishes a real unit of work: a partial_fit chunk, a few more trees, one level deeper, a weaker penalty, or more training rows. Nothing is interpolated between states that never existed.
  • The algorithm animates, not just its scores. Weighted-sum edges thicken and change sign, decision trees grow level by level, forests fill in tree by tree, boosting's corrections shrink, support vectors get ringed, Naive Bayes' bell curves sharpen, and every one of an MLP's weights changes colour each epoch.
  • Live equations with the current numbers. A side panel shows the model's formula, the objective it is minimising (with its value right now), and what this step changed: SGD's update rule, the boosting update F_M = F₀ + ν Σ h_m, a tree's root split and its impurity drop.
  • Under- and over-fitting are visible. Train and validation curves share one chart, so you watch a decision tree's training score keep improving while its validation score turns back.
  • Honest timing. Only the model's own work is timed; scoring and drawing are excluded.

🔮 At inference time

  • Unseen data streams through predict(). Held-out test rows are predicted batch by batch, and latency and throughput are measured on the real calls.
  • Every newest prediction is explained. The diagram traces the example through the model (the tree path, each tree's vote, the nearest neighbours, the forward pass), and the equation panel works the formula through with that example's numbers.
  • Every explanation is checked. Each card ends with check: model.predict(x) = … ✓ (or predict_proba / decision_function). An independent review re-ran it on all 262 Titanic test passengers: the worked equation matched the model to within 1e-13.
  • Results pile up where you can read them. A California map colours every priced district, and the Titanic passenger list fills in square by square, grouped by class and by women and men, with ✗ on every wrong call. You can watch "women and children first" appear.
  • Running scores update live: RMSE, MAE and R² for prices; accuracy, recall, the confusion matrix and a confidence histogram for survival.

🎓 In the narrated lessons

Each lesson is a 108-second, 2560×1440, 30 fps story of one algorithm that works with the sound off, in ten chapters: title → data → first guess → training → final model → prediction on an unseen example → final exam → 3-D view → more features → takeaway.

  • Training cuts from one real snapshot to the next, and the final curve equals model.predict.
  • The 3-D chapter draws the model's output as a surface over two inputs while the camera swings.
  • The "more features" chapter refits on every input and says "better" or "worse" only when a paired bootstrap (prices) or an exact McNemar test (survival) says the difference is real.
  • The Manim versions replay the same lessons with smooth reveals and transitions; every chapter still ends on exactly the matplotlib picture.
  • 🔊 The Manim versions have a voice-over: a narrator reads each chapter's own captions, with every symbol and abbreviation said in words (θ₀ as "theta zero", MLP as "multi-layer perceptron"). Where a chapter's voice runs long, its last frame holds, so a voiced lesson runs about 2½ to 3 minutes.
  • The customer-segment lessons keep the same ten chapters with no answer to learn from: the "prediction" is a customer the fitted model has never seen, placed in a segment, and the exam compares the algorithm's groups with a label that no model was shown.

🏠 California Housing: regression

sklearn.datasets.fetch_california_housing: 20,640 census districts, 8 features, target = median house value (capped at $500k). Split 60/20/20, scaled on the training rows only. Code: house_price_animations/.

📊 Live dashboards: 9 regressors, training and inference

Each dashboard is 2560×1440, in three columns: the animated algorithm, the live charts (learning curve, predicted vs actual, learned weights, residuals) and the equations at work.

📏 Linear Regression

🏋️ Training: refit on more houses each frame: a straight line plateaus early🔮 Inference: each feature's w·x push flows into Σ and lands on the price
linear_regression_training preview
▶️ Watch the full video · linear_regression_training.mp4
linear_regression_inference preview
▶️ Watch the full video · linear_regression_inference.mp4

🪢 Ridge (L2)

🏋️ Training: a weaker L2 penalty each frame: weights grow back smoothly, never exactly 0🔮 Inference: the same weighted sum, with the shrunken weights
ridge_training preview
▶️ Watch the full video · ridge_training.mp4
ridge_inference preview
▶️ Watch the full video · ridge_inference.mp4

✂️ Lasso (L1)

🏋️ Training: a weaker L1 penalty each frame: features switch on one by one (zeroed edges go dashed)🔮 Inference: only the surviving features push the price
lasso_training preview
▶️ Watch the full video · lasso_training.mp4
lasso_inference preview
▶️ Watch the full video · lasso_inference.mp4

🎯 SGD Regressor

🏋️ Training: partial_fit on 1/16 of an epoch: averaged weights walk downhill on squared error🔮 Inference: the learned weighted sum, house by house
sgd_training preview
▶️ Watch the full video · sgd_training.mp4
sgd_inference preview
▶️ Watch the full video · sgd_inference.mp4

🌳 Decision Tree

🏋️ Training: one level deeper each frame: training error falls, validation error turns back up🔮 Inference: the house's root-to-leaf path through the splits, in real units
decision_tree_training preview
▶️ Watch the full video · decision_tree_training.mp4
decision_tree_inference preview
▶️ Watch the full video · decision_tree_inference.mp4

🌲 Random Forest

🏋️ Training: more bootstrapped trees each frame (warm_start)🔮 Inference: 12 trees light up their paths and vote; a strip shows all 100 votes and the average
random_forest_training preview
▶️ Watch the full video · random_forest_training.mp4
random_forest_inference preview
▶️ Watch the full video · random_forest_inference.mp4

🚀 Gradient Boosting

🏋️ Training: 5 more shallow trees each frame, each fitted to the residuals🔮 Inference: the price climbing from F₀ to the prediction, tree by tree
gradient_boosting_training preview
▶️ Watch the full video · gradient_boosting_training.mp4
gradient_boosting_inference preview
▶️ Watch the full video · gradient_boosting_inference.mp4

📍 K-Nearest Neighbours (k=10)

🏋️ Training: more houses memorised on the California map🔮 Inference: the house (a star) linked to its 10 nearest neighbours
knn_training preview
▶️ Watch the full video · knn_training.mp4
knn_inference preview
▶️ Watch the full video · knn_inference.mp4

🧠 MLP (64-32)

🏋️ Training: one Adam epoch: all 2,592 weights change on screen🔮 Inference: hidden units firing (ReLU > 0) and the signal each edge carries
mlp_training preview
▶️ Watch the full video · mlp_training.mp4
mlp_inference preview
▶️ Watch the full video · mlp_inference.mp4

🏁 Comparison scenes

🏁 The Algorithm Race
all 9 regressors train in lockstep; the leaderboard re-sorts, then a test-set podium
algorithm_race preview
▶️ Watch the full video · algorithm_race.mp4
🗺️ Watch the model learn California
4 models price the same typical house at every point in the state
california_map preview
▶️ Watch the full video · california_map.mp4

🎓 Narrated lessons (matplotlib): one algorithm each

The model learns house value from median income alone, so the model itself is the curve you watch move; the 3-D chapter then adds house age. Code: house_price_animations/house_anim/lessons/.

📏 Linear regression
40 full-batch gradient-descent steps, on the real MSE bowl
linear_regression_lesson preview
▶️ Watch the full 108-second lesson · linear_regression_lesson.mp4
〰️ Polynomial regression
degree 1 → 12: watch it over-fit 30 districts
polynomial_regression_lesson preview
▶️ Watch the full 108-second lesson · polynomial_regression_lesson.mp4
🪢 Ridge
a stronger L2 penalty: weights shrink smoothly
ridge_lesson preview
▶️ Watch the full 108-second lesson · ridge_lesson.mp4
✂️ Lasso
a stronger L1 penalty: weights switch off (exactly 0)
lasso_lesson preview
▶️ Watch the full 108-second lesson · lasso_lesson.mp4
🌳 Decision tree
one more best-first split, 1 → 14 leaves
decision_tree_lesson preview
▶️ Watch the full 108-second lesson · decision_tree_lesson.mp4
🌲 Random forest
more bootstrapped trees, averaged
random_forest_lesson preview
▶️ Watch the full 108-second lesson · random_forest_lesson.mp4
🚀 Gradient boosting
trees fitted to the residuals
gradient_boosting_lesson preview
▶️ Watch the full 108-second lesson · gradient_boosting_lesson.mp4
📍 k-nearest neighbours
k from 1 to 1,024; validation picks k
knn_lesson preview
▶️ Watch the full 108-second lesson · knn_lesson.mp4
🧠 Neural network (MLP)
real Adam training of a 1→8→8→1 ReLU network, all 97 weights
mlp_lesson preview
▶️ Watch the full 108-second lesson · mlp_lesson.mp4

🎞️ Voiced lessons (Manim) 🔊

The same nine lessons, played with Manim, with a voice-over: turn the sound on. The playlist opens with an introduction (who it is for, and what is real in what you see) and closes with a conclusion. Code: house_price_manim_lessons/.

👋 Introduction
who the series is for, the data, the nine algorithms and how a lesson runs
introduction preview
▶️ Watch the introduction (2:19) 🔊 · introduction.mp4
🎓 Conclusion
both scoreboards, and three lessons the numbers support
conclusion preview
▶️ Watch the conclusion (1:29) 🔊 · conclusion.mp4
📏 Linear regression
40 full-batch gradient-descent steps, on the real MSE bowl
linear_regression_lesson preview
▶️ Watch the full voiced lesson (2:29) 🔊 · linear_regression_lesson.mp4
〰️ Polynomial regression
degree 1 → 12: watch it over-fit 30 districts
polynomial_regression_lesson preview
▶️ Watch the full voiced lesson (2:25) 🔊 · polynomial_regression_lesson.mp4
🪢 Ridge
a stronger L2 penalty: weights shrink smoothly
ridge_lesson preview
▶️ Watch the full voiced lesson (2:28) 🔊 · ridge_lesson.mp4
✂️ Lasso
a stronger L1 penalty: weights switch off (exactly 0)
lasso_lesson preview
▶️ Watch the full voiced lesson (2:31) 🔊 · lasso_lesson.mp4
🌳 Decision tree
one more best-first split, 1 → 14 leaves
decision_tree_lesson preview
▶️ Watch the full voiced lesson (2:21) 🔊 · decision_tree_lesson.mp4
🌲 Random forest
more bootstrapped trees, averaged
random_forest_lesson preview
▶️ Watch the full voiced lesson (2:25) 🔊 · random_forest_lesson.mp4
🚀 Gradient boosting
trees fitted to the residuals
gradient_boosting_lesson preview
▶️ Watch the full voiced lesson (2:19) 🔊 · gradient_boosting_lesson.mp4
📍 k-nearest neighbours
k from 1 to 1,024; validation picks k
knn_lesson preview
▶️ Watch the full voiced lesson (2:28) 🔊 · knn_lesson.mp4
🧠 Neural network (MLP)
real Adam training of a 1→8→8→1 ReLU network, all 97 weights
mlp_lesson preview
▶️ Watch the full voiced lesson (2:26) 🔊 · mlp_lesson.mp4

🚢 Titanic: classification

OpenML's titanic: 1,309 passengers. The boat and body columns are dropped, because they are only known after the sinking and would leak the answer. Stratified 60/20/20 split, so every split keeps the same 38% survival rate; gaps are filled from the training passengers only. Code: titanic_animations/.

📊 Live dashboards: 9 classifiers, training and inference

Training shows the accuracy learning curve, the ROC curve with AUC, the learned weights and the confusion matrix. Inference shows the passenger list, running accuracy and recall, and how sure the model is. Blue means survived, red means did not, and the neutral grey midpoint is the 0.5 threshold.

📈 Logistic Regression

🏋️ Training: a larger C each frame: weights grow from zero, validation passengers separate on the S-curve🔮 Inference: inputs → weighted edges → Σ → σ → P(survive), and the passenger's point on the S-curve
logistic_regression_training preview
▶️ Watch the full video · logistic_regression_training.mp4
logistic_regression_inference preview
▶️ Watch the full video · logistic_regression_inference.mp4

🎯 SGD Classifier (logistic loss)

🏋️ Training: partial_fit on 1/8 of an epoch: averaged weights walk downhill on log loss🔮 Inference: the same σ diagram with the SGD weights
sgd_training preview
▶️ Watch the full video · sgd_training.mp4
sgd_inference preview
▶️ Watch the full video · sgd_inference.mp4

🛡️ Support Vector Machine (RBF)

🏋️ Training: refit on more passengers: support vectors ringed on a PCA map, sized by α🔮 Inference: the 10 strongest α·y·K pulls, and the signed margin f(x)
svm_training preview
▶️ Watch the full video · svm_training.mp4
svm_inference preview
▶️ Watch the full video · svm_inference.mp4

🔔 Gaussian Naive Bayes

🏋️ Training: count more passengers: a survived / did-not-survive bell curve per feature sharpens🔮 Inference: the passenger's value on each curve and its log-likelihood ratio
naive_bayes_training preview
▶️ Watch the full video · naive_bayes_training.mp4
naive_bayes_inference preview
▶️ Watch the full video · naive_bayes_inference.mp4

🌳 Decision Tree

🏋️ Training: one level deeper each frame, nodes coloured by survival share🔮 Inference: the yes/no questions: “male? yes · age ≤ 12.5? no …” down to the leaf
decision_tree_training preview
▶️ Watch the full video · decision_tree_training.mp4
decision_tree_inference preview
▶️ Watch the full video · decision_tree_inference.mp4

🌲 Random Forest

🏋️ Training: more bootstrapped trees each frame (warm_start)🔮 Inference: every tree's P(survive), and the forest's average
random_forest_training preview
▶️ Watch the full video · random_forest_training.mp4
random_forest_inference preview
▶️ Watch the full video · random_forest_inference.mp4

🚀 Gradient Boosting

🏋️ Training: 5 more trees each frame, correcting the log-odds🔮 Inference: P(survive) climbing from the 38% base rate, tree by tree
gradient_boosting_training preview
▶️ Watch the full video · gradient_boosting_training.mp4
gradient_boosting_inference preview
▶️ Watch the full video · gradient_boosting_inference.mp4

📍 K-Nearest Neighbours (k=11)

🏋️ Training: more passengers memorised on a PCA map🔮 Inference: the 11 most similar passengers and how many survived
knn_training preview
▶️ Watch the full video · knn_training.mp4
knn_inference preview
▶️ Watch the full video · knn_inference.mp4

🧠 MLP (32-16)

🏋️ Training: one Adam epoch per frame🔮 Inference: activations firing into a sigmoid output
mlp_training preview
▶️ Watch the full video · mlp_training.mp4
mlp_inference preview
▶️ Watch the full video · mlp_inference.mp4

🏁 Comparison scenes

🏁 The Algorithm Race
9 classifiers race on validation error, then a test-set podium
algorithm_race preview
▶️ Watch the full video · algorithm_race.mp4
🧭 Who survives?
4 models paint P(survive) for every age, class and sex as they train
survival_landscape preview
▶️ Watch the full video · survival_landscape.mp4

🎓 Narrated lessons (matplotlib): one classifier each

Each classifier learns survival from age, fare and sex: two maps (women | men), age across, fare on a log scale, shaded by the model's score with its decision boundary drawn and every misclassified training passenger circled. Code: titanic_animations/titanic_anim/lessons/.

📈 Logistic regression
full-batch gradient descent on the log loss
logistic_regression_lesson preview
▶️ Watch the full 108-second lesson · logistic_regression_lesson.mp4
⚡ Perceptron
online updates; a signed score, never called a probability
perceptron_lesson preview
▶️ Watch the full 108-second lesson · perceptron_lesson.mp4
🛡️ Linear SVM
SGD epochs on hinge loss; dashed ±1 margins
linear_svm_lesson preview
▶️ Watch the full 108-second lesson · linear_svm_lesson.mp4
🔔 Naive Bayes
priors and per-class bell curves update
naive_bayes_lesson preview
▶️ Watch the full 108-second lesson · naive_bayes_lesson.mp4
🌳 Decision tree
one more best-first split, 1 → 12 leaves
decision_tree_lesson preview
▶️ Watch the full 108-second lesson · decision_tree_lesson.mp4
🌲 Random forest
more bootstrapped trees, probabilities averaged
random_forest_lesson preview
▶️ Watch the full 108-second lesson · random_forest_lesson.mp4
🚀 Gradient boosting
trees added in log-odds
gradient_boosting_lesson preview
▶️ Watch the full 108-second lesson · gradient_boosting_lesson.mp4
📍 k-nearest neighbours
k from 1 to 256; validation picks k
knn_lesson preview
▶️ Watch the full 108-second lesson · knn_lesson.mp4
🧠 Neural network (MLP)
real Adam training of a 3→8→8→1 network
mlp_lesson preview
▶️ Watch the full 108-second lesson · mlp_lesson.mp4

🎞️ Voiced lessons (Manim) 🔊

The same nine lessons, played with Manim, with a voice-over: turn the sound on. The playlist opens with an introduction (who it is for, and what is real in what you see) and closes with a conclusion. Code: titanic_manim_lessons/.

👋 Introduction
who the series is for, the data, the nine algorithms and how a lesson runs
introduction preview
▶️ Watch the introduction (2:25) 🔊 · introduction.mp4
🎓 Conclusion
both scoreboards, and three lessons the numbers support
conclusion preview
▶️ Watch the conclusion (1:25) 🔊 · conclusion.mp4
📈 Logistic regression
full-batch gradient descent on the log loss
logistic_regression_lesson preview
▶️ Watch the full voiced lesson (2:24) 🔊 · logistic_regression_lesson.mp4
⚡ Perceptron
online updates; a signed score, never called a probability
perceptron_lesson preview
▶️ Watch the full voiced lesson (2:18) 🔊 · perceptron_lesson.mp4
🛡️ Linear SVM
SGD epochs on hinge loss; dashed ±1 margins
linear_svm_lesson preview
▶️ Watch the full voiced lesson (2:24) 🔊 · linear_svm_lesson.mp4
🔔 Naive Bayes
priors and per-class bell curves update
naive_bayes_lesson preview
▶️ Watch the full voiced lesson (2:21) 🔊 · naive_bayes_lesson.mp4
🌳 Decision tree
one more best-first split, 1 → 12 leaves
decision_tree_lesson preview
▶️ Watch the full voiced lesson (2:14) 🔊 · decision_tree_lesson.mp4
🌲 Random forest
more bootstrapped trees, probabilities averaged
random_forest_lesson preview
▶️ Watch the full voiced lesson (2:15) 🔊 · random_forest_lesson.mp4
🚀 Gradient boosting
trees added in log-odds
gradient_boosting_lesson preview
▶️ Watch the full voiced lesson (2:15) 🔊 · gradient_boosting_lesson.mp4
📍 k-nearest neighbours
k from 1 to 256; validation picks k
knn_lesson preview
▶️ Watch the full voiced lesson (2:26) 🔊 · knn_lesson.mp4
🧠 Neural network (MLP)
real Adam training of a 3→8→8→1 network
mlp_lesson preview
▶️ Watch the full voiced lesson (2:23) 🔊 · mlp_lesson.mp4

🛒 Wholesale customers: market segmentation

UCI's Wholesale customers (OpenML data id 1511): what 440 customers of a wholesale distributor spent in a year on six kinds of products. There is no target: nobody tells an algorithm which segment a customer belongs to. Spending is used as log10, and the customers are split 60/20/20 (seed 42). Data: Cardoso, M. (2013), Wholesale customers, UCI Machine Learning Repository, doi.org/10.24432/C5030X, CC BY 4.0. Code: customer_segments_animations/.

One label does exist: each customer's sales channel (hotel, restaurant or café; or retail). It is hidden from every model, split and choice, and only checks the finished result: on the 88 test customers, how far do an algorithm's groups agree with it? The measure is the adjusted Rand index, where random segments score 0 and the same grouping scores 1.

🎞️ Voiced lessons (Manim) 🔊

Nine unsupervised algorithms, one lesson each, played with Manim, with a voice-over: turn the sound on. A lesson runs the same ten chapters as the supervised ones: the data, where the algorithm starts, its real steps, the finished segments, one customer it never saw, a final exam against the hidden channel, a 3-D view of what the algorithm measures, the same algorithm given all six kinds of spending, and the takeaway. The lessons plot grocery against detergents and paper; the UMAP lesson plots the map it makes of all six. The playlist opens with an introduction (who it is for, and what is real in what you see) and closes with a conclusion. Code: customer_segments_manim_lessons/.

👋 Introduction
who the series is for, the data and its one hidden label, the nine algorithms and how a lesson runs
introduction preview
▶️ Watch the introduction (2:40) 🔊 · introduction.mp4
🎓 Conclusion
how far each algorithm's groups agree with the hidden label, and three lessons the numbers support
conclusion preview
▶️ Watch the conclusion (1:28) 🔊 · conclusion.mp4
🎯 k-means
centres moved by Lloyd's algorithm until no customer changes segment; k chosen by silhouette
kmeans_lesson preview
▶️ Watch the full voiced lesson (2:37) 🔊 · kmeans_lesson.mp4
🗂️ Hierarchical clustering
Ward's merges replayed into a tree, then cut into segments where the silhouette is best
hierarchical_lesson preview
▶️ Watch the full voiced lesson (3:12) 🔊 · hierarchical_lesson.mp4
🔔 Gaussian mixture
bell-shaped groups stretched by expectation–maximisation, every customer shared between them
gaussian_mixture_lesson preview
▶️ Watch the full voiced lesson (3:07) 🔊 · gaussian_mixture_lesson.mp4
🏙️ DBSCAN
density-based spatial clustering of applications with noise: crowded regions grow from core customer to core customer, and the rest is left as noise
dbscan_lesson preview
▶️ Watch the full voiced lesson (3:12) 🔊 · dbscan_lesson.mp4
⛰️ Mean shift
a seed on every customer drifts to where customers crowd; nearby spots merge into peaks
mean_shift_lesson preview
▶️ Watch the full voiced lesson (3:04) 🔊 · mean_shift_lesson.mp4
🕸️ Spectral clustering
a nearest-neighbour graph, laid out in its own coordinates, then cut
spectral_lesson preview
▶️ Watch the full voiced lesson (3:06) 🔊 · spectral_lesson.mp4
📐 Principal component analysis (PCA)
one line through the customers squeezes two inputs into one number, which k-means then cuts
pca_lesson preview
▶️ Watch the full voiced lesson (2:58) 🔊 · pca_lesson.mp4
🗺️ UMAP
uniform manifold approximation and projection: a map of all six kinds of spending settles over 500 recorded epochs, then k-means cuts it
umap_lesson preview
▶️ Watch the full voiced lesson (2:40) 🔊 · umap_lesson.mp4
🌲 Isolation forest
a forest of random cuts, grown from 1 to 100 trees, flags the customers easiest to isolate
isolation_forest_lesson preview
▶️ Watch the full voiced lesson (3:01) 🔊 · isolation_forest_lesson.mp4

🏆 Scoreboard

Test-set results from the live dashboards (all 8 features). The lessons use one or three features on purpose, so each picture tells one story; their scores are in each lessons folder's lessons_summary.csv.

🏠 Regressor Test RMSE Test R² 🚢 Classifier Test accuracy
🥇 Gradient Boosting $49.7k 0.812 🥇 Gradient Boosting 83.6%
🥈 Random Forest $50.9k 0.802 🥇 MLP (32-16) 83.6%
🥉 MLP (64-32) $53.2k 0.784 🥉 KNN (k=11) 82.8%
KNN (k=10) $64.1k 0.686 SVM (RBF) 82.4%
Decision Tree (depth 18) $69.6k 0.631 Random Forest 79.8%
Lasso $74.8k 0.573 Logistic Regression 79.4%
Linear Regression $75.0k 0.571 SGD (logistic) 77.1%
Ridge $75.0k 0.571 Naive Bayes 77.1%
SGD Regressor $77.3k 0.544 Decision Tree (depth 14) 74.0%

The decision trees are reported at the end of their depth sweeps, which over-fit on purpose: that is the lesson their videos teach.

🛒 Customer segments: agreement with the hidden channel

No algorithm was shown the customers' sales channel, so it can judge them all. This is the adjusted Rand index between each lesson's groups and the channel on the 88 test customers (random segments score 0, the same grouping scores 1), read from the lessons' own lessons_summary.csv.

🛒 Algorithm Agreement
🕸️ Spectral clustering 0.52
🎯 k-means 0.40
📐 Principal component analysis (PCA) 0.39
🗂️ Hierarchical clustering 0.37
🗺️ UMAP 0.34
⛰️ Mean shift 0.30
🔔 Gaussian mixture 0.26
🌲 Isolation forest −0.03
🏙️ DBSCAN −0.07

A low agreement is not a failed lesson. DBSCAN finds one crowded mass and tells you who is unusual, and the isolation forest's flags have nothing to do with the channel: both videos say so.

📂 Project layout

Each dataset lives in its own folder; anything shared lives in a dataset-neutral kit.

animated-machine-learning-algorithm/
├── ml_animation_kit/           🧰 animkit: recorder, playback, dashboard chrome, equation panel,
│                                  tree and network drawing, and the narrated-lesson director
├── house_price_animations/     🏠 house_anim: regressor dashboards, scenes and lessons
├── titanic_animations/         🚢 titanic_anim: classifier dashboards, scenes and lessons
├── manim_lesson_kit/           🎞️ manimkit: plays any lesson with Manim instead of matplotlib
├── house_price_manim_lessons/  🏠 the house-price lessons, played with Manim
├── titanic_manim_lessons/      🚢 the Titanic lessons, played with Manim
├── customer_segments_animations/     🛒 segments_anim: clustering lessons (unsupervised)
└── customer_segments_manim_lessons/  🛒 the customer-segment lessons, played with Manim
Folder README
ml_animation_kit/ shared matplotlib engine
house_price_animations/ regressor dashboards and lessons
titanic_animations/ classifier dashboards and lessons
manim_lesson_kit/ shared Manim player
house_price_manim_lessons/ house-price lessons in Manim
titanic_manim_lessons/ Titanic lessons in Manim
customer_segments_animations/ clustering lessons
customer_segments_manim_lessons/ customer-segment lessons in Manim

🚀 Quick start

You need Python 3.10+ and ffmpeg on your PATH (brew install ffmpeg). Nothing is installed as a package: each project finds the kit next to it.

git clone https://github.com/di37/animated-machine-learning-algorithm.git
cd animated-machine-learning-algorithm

🏠 California Housing

cd house_price_animations
pip install -r requirements.txt
python animate.py --model gradient_boosting       # live window + training and inference videos
python animate.py --scene race                    # The Algorithm Race
python animate.py --scene map                     # Watch the model learn California
python animate_lessons.py --model decision_tree   # one narrated lesson

🚢 Titanic

cd titanic_animations
pip install -r requirements.txt
python animate_titanic.py --model random_forest
python animate_titanic.py --scene race
python animate_titanic.py --scene landscape       # Who survives?
python animate_titanic_lessons.py --model knn

🛒 Customer segments (the matplotlib render is the quick look; the published videos are the Manim ones)

cd customer_segments_animations
pip install -r requirements.txt
python animate_segment_lessons.py --model kmeans

🎞️ Manim lessons (set up manim_lesson_kit/.venv first; its README shows how)

cd house_price_manim_lessons
../manim_lesson_kit/.venv/bin/python animate_manim_lessons.py --model linear_regression

🔊 Voice-over (ElevenLabs: put ELEVENLABS_API_KEY=... in a .env file at the repo root, which git ignores)

cd house_price_manim_lessons
python3 voice_manim_lessons.py --model linear_regression   # --script-only shows the words first, free

Every command takes --list and --help. Dashboards also accept --no-live (record only), --phase training|inference|both and --format gif.

🔒 Truthfulness rules

These are enforced by the test suites, not just promised:

  • 🔁 Real states only. Every curve, boundary, weight and metric on screen comes from a real model state; frames are held, never interpolated into states that did not exist.
  • ✅ Checked predictions. A worked prediction must reproduce predict, predict_proba or decision_function before it may print ✓.
  • 🧪 No leakage. Scalers and imputation are fitted on training rows only; test rows appear only at inference and in the final exam.
  • 🎯 Honest labels. Margin models (SVM, perceptron) show a signed score, never a "probability".
  • 🙈 Hidden labels stay hidden. In the customer-segment lessons no model, split or choice reads the sales channel; it only scores the finished groups on the test customers.
  • ⚖️ Honest verdicts. "Better" or "worse" is claimed only when a paired bootstrap or exact McNemar test supports it.
  • ⏱️ Honest timing. Fit and predict times count only the model's own work.

⭐ Spread the word

If these videos helped an algorithm click for you:

  • ⭐ Star the repo, so more learners find it.
  • 🔁 Share a video with a friend, a class or a study group. Every ▶️ link plays in the browser.
  • 🧑‍🏫 Teach with it: the matplotlib lessons are 108 seconds and work with the sound off; the Manim lessons have a voice-over.

IR · Isham Rashik · AI Engineer · Making AI simplified for all

استكشف مشاريع مشابهة ومرتبطة

جارٍ التحميل…