The honest answer first
JavaScript is not the usual language for machine learning. Python is, by a wide margin, and if you go on to work in this field professionally you will use Python. It is worth saying that plainly at the start rather than pretending otherwise.
So why is this course in JavaScript? Because the goal here is not to train large models. It is to see clearly what is happening inside small ones, and for that JavaScript is better.
You can see everything
In Python you would write:
model.fit(X, y)
That line is doing everything this course is about, and it is doing it out of sight. It is convenient, and it is exactly what you want once you understand the contents. Before then it teaches you nothing.
In this course there is no library to hide behind. If gradient descent runs, it runs because you wrote the loop. When something goes wrong you can read every line involved.
Drawing is built in
This is the practical reason. A browser gives you a canvas, a mouse, and animation with no setup at all.
That matters because most of these ideas are geometric. A loss is a surface. Gradient descent is a ball rolling downhill. A classifier is a boundary between regions. Overfitting is a curve bending itself around noise. All of these are much easier to understand when you can watch them move than when you read the equations.
Being able to drag a line with the mouse and see the loss change in real time is worth more than several pages of explanation. In the browser, that costs a few lines of code.
Nothing to install
Every example in this course runs in a single HTML file, opened in a browser you already have. No environment setup, no package manager, no version conflicts. You can also paste any of the code straight into the console.
This removes a common way of getting stuck, where an hour disappears into installation problems before any learning happens.
You already read it
If JavaScript is the language you think in, then a loop written in it is transparent to you. Attention that would go into parsing unfamiliar syntax goes into the idea instead. When we derive backpropagation, you want all of your attention on the derivation.
Where JavaScript falls down
It is only fair to state the limits.
- It is slow for heavy numerical work. Our examples use tens or hundreds of data points, which is fine. Millions would not be.
- There is no GPU support in what we are writing. Training anything large is out of reach.
- The library ecosystem is much smaller. TensorFlow.js exists and is good, but the research world publishes in Python.
None of this affects learning the fundamentals, because the mathematics is the same in every language. A gradient does not care what it is written in. Once you understand these ideas you can move to Python in an afternoon, and you will read its libraries with a clear picture of what they are doing.
Try this before the next lesson
- Open your browser console and paste in the converter from lesson one. Confirm it runs with no setup.
- Find the documentation for a machine learning library you have heard of and read the description of its main training function. How much of it can you already explain?