Machine learning is good at classifying and labelling data. The premise of every machine learning problem is:
If you want to get started, predicting numbers tends to be easier than predicting images, so in this example we're trying to fit a curve to a bunch of data (this is the same example from the TensorFlow site but with waaaaay more code comments and a prettier graph).
We are given a bunch of points (for
x between -1 and 1, calculate a
y according to
y = a * x^3 + b * x^2 + c * x + d -- we know this is the secret formula but we don't know the
values of those
Our goal is to learn these coefficients, so that if we're given a new
x value, we can say what the
y value should be.
The blue dots are the training points we were given. The red dots would be our guesses,
based on our initial, default coefficients (hella incorrect!). Once you click the
button, the green dots show how our coefficients are getting better. After you see the default
example, check what happens if you change the shape of the data, or we are given fewer data points or fewer iterations!
Most machine learning algorithms follow this pattern:
a,b,c,dcoefficients), we initialize them to some random values. We could now use them to make predictions, but they would be teeeeeerrible because they're just random.
(x,y)of training data we were given. We take the
xvalue, and based on these coefficients we have estimated, we predict what the
yvalue would be. We then look at the correct
yvalue from the original training data, calculate the difference between the two, and then adjust our coefficients so that our predicted value gets closer to the correct one.
You can look at the code for the demo on Glitch. I tried to comment most lines of the code with either what the algorithm or TensorFlow are doing (especially when TensorFlow is actually doing a looooot of heavy lifting behind the scenes). I hope it helps!
I'm Tama 👋 I turn down every ad and affiliate. I started this website as a place to document everything I learned. If you enjoy my content, please consider supporting what I do.