Coding Challenge 187: Bayes Theorem
Summary
This video details the implementation of a Naive Bayes text classifier in JavaScript, covering Bayes' Theorem, word frequency analysis, and Laplacian smoothing. It's highly valuable for students learning foundational AI and machine learning concepts, offering a practical, step-by-step guide to building a sentiment classifier.
Description
In this coding challenge, I struggle my way through implementing a Naive Bayes text classifier in JavaScript using p5.js. I explain Bayes' theorem, demonstrate word frequency analysis, implement Laplacian smoothing, and build a working sentiment classifier that runs entirely in the browser. Code: https://thecodingtrain.com/challenges/187-bayesian-text-classification ๐ Watch this video ad-free on Nebula https://nebula.tv/videos/codingtrain-coding-challenge-187-bayes-classifier p5.js Web Editor Sketches: ๐น๏ธ Text Classifier - Initial Version: https://editor.p5js.org/codingtrain/sketches/RZ8a1z4DN ๐น๏ธ Text Classifier - Refactored Version: https://editor.p5js.org/codingtrain/sketches/P3ngrAANX ๐น๏ธ Text Classifier - File Loading Version: https://editor.p5js.org/codingtrain/sketches/WowR2Q9xg ๐ฅ Previous: https://youtu.be/5iSAvzU2WYY?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH ๐ฅ All: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH References: ๐ Naive Bayes Classifier: https://en.wikipedia.org/wiki/Naive_Bayes_classifier ๐ Laplacian Smoothing: https://en.wikipedia.org/wiki/Additive_smoothing Videos: ๐ https://youtu.be/unm0BLor8aE ๐ https://youtu.be/7DG3kCDx53c?list=PLRqwX-V7Uu6YEypLuls7iidwHMdCM6o2w ๐บ https://youtu.be/HZGCoVF3YvM ๐ https://youtu.be/0Ad5Frf8NBM Live Stream Archives: ๐ด https://youtube.com/live/TsBDm0P0qaA Related Coding Challenges: ๐ https://youtu.be/unm0BLor8aE ๐ https://youtu.be/eGFJ8vugIWA Timestamps: 0:00:00 Hello! 0:03:34 Explaining Bayes' Theorem 0:12:07 What is Naive Bayes? 0:13:49 Setting up the Classifier in p5.js 0:15:41 Coding the train() function 0:22:14 Coding the classify() Function 0:24:45 Revising the train() function 0:29:06 Implementing Probability Calculations 0:33:24 Laplacian (Additive) Smoothing 0:42:21 Ignoring the enominator (Normalization) 0:45:36 Quick User Interface 0:49:42 Final thoughts and next steps. Editing by Mathieu Blanchette Animations by Jason Heglund Music from Epidemic Sound ๐




