r/coding • u/gniziemazity • Oct 11 '20
Learn a basic machine learning method if all you know is some JavaScript. No external libraries are used.
https://youtu.be/QXB1ytG95gs2
0
Oct 11 '20
[deleted]
7
u/1-Ceth Oct 12 '20
It's a fun exercise that might expand a basic understanding, nobody's building deepfakes or pushing the boundaries of AI with this tutorial
2
3
u/gniziemazity Oct 12 '20
Here, I chose JavaScript because everyone has a web browser nowadays and one can write a webpage like this without any tools installed; it is also convenient to access the camera. I wanted this because many machine learning tutorials work with ready datasets and do not explain two important steps: data collection and feature extraction.
JavaScript is also the most used programming language, so, I hoped this could be a bridge between knowing programming and machine learning, which can seem like a scary topic.
The method here is very basic: the nearest neighbor classifier. But it is intuitive once you understand the abstraction from the real world to the feature space. It can also be easily extended to the more powerful k-nearest neighbor. For more sophisticated methods, I recommend to use libraries and JavaScript is not ideal.
We actually had success in teaching this in high school: http://cs.uef.fi/sipu/pub/KoliPaper.pdf
0
Oct 12 '20
[deleted]
1
u/gniziemazity Oct 12 '20
Wow! You took the time to read the manuscript. Thank you.
Indeed, it was just an analysis on students' intrinsic motivation, and they were guided to build only this particular system. But the point is that the knowledge necessary to build this was already there (part of the curriculum). They knew the algorithms already and the exercise taught how putting simple components together can make something more sophisticated.
Based on discussions with the students, I believe some could implement this by themselves. And even extend it by either adding a third feature or by implementing the k-nearest neighbor classifier as sorting is also part of their curriculum.
4
Oct 12 '20
This is the kind of gateway video that sparks a developing interest. Many years back I had a similar experience reading a tutorial on building an IRC chat bot using markov chaining. I hope this and similar videos give newcomers that same joy I got.
2
u/gniziemazity Oct 12 '20
I hope so too. Do you happen to still have the link to that tutorial?
2
Oct 12 '20
Unfortunately I cannot find it, but I'm sure there are better tutorials out there these days and in a more common language than Perl. I did however find this SO article which may have been one of my other sources for understanding the basic concept: https://stackoverflow.com/questions/5306729/how-do-markov-chain-chatbots-work#5307230
The key takeaways for me not mentioned in anything I was reading is that users paste a lot of information that isn't useful and can undo a lot of hard work training... sentence fragments, URLs, images... and some users are purposefully abusive. So being conservative on what we were learning was as important as a functioning algorithm. I always started with a training file to establish a "base personality" for the bot and then it adapted from there to pick up on quirks and sentence structures from users in the channel. It even distinguished English from Spanish in its replies (as the word pairs were mostly exclusive).
1
u/gniziemazity Oct 12 '20
I see. Sounds like a nice learning experience: especially interesting when simple rules make a complex system like that work.
4
u/CraZyBob Oct 12 '20
I don't have a PhD but I understand ML.
Then again I don't understand JavaScript either so ¯\(ツ)/¯
3
0
Oct 12 '20
[deleted]
2
u/CraZyBob Oct 12 '20
Assisted in implementing and currently maintaining an ML pipeline for data transformation
5
u/DnBenjamin Oct 11 '20
"what the fu........nction is doing is..." 😆