Uploaded October 2025 | Updated September 2026, 1 week ago
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: thecodingtrain.com/challenges/187-bayesian-text-classification
π Watch this video ad-free on Nebula nebula.tv/videos/codingtrain-coding-challenge-187-bayes-classifier
p5.js Web Editor Sketches:
πΉοΈ Text Classifier - Initial Version: editor.p5js.org/codingtrain/sketches/RZ8a1z4DN
πΉοΈ Text Classifier - Refactored Version: editor.p5js.org/codingtrain/sketches/P3ngrAANX
πΉοΈ Text Classifier - File Loading Version: editor.p5js.org/codingtrain/sketches/WowR2Q9xg
π₯ Previous: youtu.be/5iSAvzU2WYY?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
π₯ All: youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
References:
π Naive Bayes Classifier: en.wikipedia.org/wiki/Naive_Bayes_classifier
π Laplacian Smoothing: en.wikipedia.org/wiki/Additive_smoothing
Videos:
π youtu.be/unm0BLor8aE
π youtu.be/7DG3kCDx53c?list=PLRqwX-V7Uu6YEypLuls7iidwHMdCM6o2w
πΊ youtu.be/HZGCoVF3YvM
π youtu.be/0Ad5Frf8NBM
Live Stream Archives:
π΄ youtube.com/live/TsBDm0P0qaA
Related Coding Challenges:
π youtu.be/unm0BLor8aE
π 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
π Website: thecodingtrain.com
πΎ Share Your Creation! thecodingtrain.com/guides/passenger-showcase-guide
π© Suggest Topics: github.com/CodingTrain/Suggestion-Box
π‘ GitHub: github.com/CodingTrain
π¬ Discord: thecodingtrain.com/discord
π Membership: youtube.com/thecodingtrain/join
π Store: standard.tv/codingtrain
ποΈ Twitter: twitter.com/thecodingtrain
πΈ Instagram: instagram.com/the.coding.train
π₯ youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
π₯ youtube.com/playlist?list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA
π p5.js: p5js.org
π p5.js Web Editor: editor.p5js.org
π Processing: processing.org
π Code of Conduct: github.com/CodingTrain/Code-of-Conduct
This description was auto-generated. If you see a problem, please open an issue: github.com/CodingTrain/thecodingtrain.com/issues/new
#bayestheorem #textclassification #naivebayes #sentimentanalysis #naturallanguageprocessing #machinelearning #wordfrequency #laplaciansmoothing #javascript #p5js
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: thecodingtrain.com/challenges/187-bayesian-text-classification
π Watch this video ad-free on Nebula nebula.tv/videos/codingtrain-coding-challenge-187-bayes-classifier
p5.js Web Editor Sketches:
πΉοΈ Text Classifier - Initial Version: editor.p5js.org/codingtrain/sketches/RZ8a1z4DN
πΉοΈ Text Classifier - Refactored Version: editor.p5js.org/codingtrain/sketches/P3ngrAANX
πΉοΈ Text Classifier - File Loading Version: editor.p5js.org/codingtrain/sketches/WowR2Q9xg
π₯ Previous: youtu.be/5iSAvzU2WYY?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
π₯ All: youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
References:
π Naive Bayes Classifier: en.wikipedia.org/wiki/Naive_Bayes_classifier
π Laplacian Smoothing: en.wikipedia.org/wiki/Additive_smoothing
Videos:
π youtu.be/unm0BLor8aE
π youtu.be/7DG3kCDx53c?list=PLRqwX-V7Uu6YEypLuls7iidwHMdCM6o2w
πΊ youtu.be/HZGCoVF3YvM
π youtu.be/0Ad5Frf8NBM
Live Stream Archives:
π΄ youtube.com/live/TsBDm0P0qaA
Related Coding Challenges:
π youtu.be/unm0BLor8aE
π 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
π Website: thecodingtrain.com
πΎ Share Your Creation! thecodingtrain.com/guides/passenger-showcase-guide
π© Suggest Topics: github.com/CodingTrain/Suggestion-Box
π‘ GitHub: github.com/CodingTrain
π¬ Discord: thecodingtrain.com/discord
π Membership: youtube.com/thecodingtrain/join
π Store: standard.tv/codingtrain
ποΈ Twitter: twitter.com/thecodingtrain
πΈ Instagram: instagram.com/the.coding.train
π₯ youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
π₯ youtube.com/playlist?list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA
π p5.js: p5js.org
π p5.js Web Editor: editor.p5js.org
π Processing: processing.org
π Code of Conduct: github.com/CodingTrain/Code-of-Conduct
This description was auto-generated. If you see a problem, please open an issue: github.com/CodingTrain/thecodingtrain.com/issues/new
#bayestheorem #textclassification #naivebayes #sentimentanalysis #naturallanguageprocessing #machinelearning #wordfrequency #laplaciansmoothing #javascript #p5js










