Linear Regression
Let's get physical
Sometimes, nothing beats holding a copy of a book in your hands. Writing in the margins, highlighting sentences, folding corners. So this book is also available from Amazon as a paperback.
Linear regression is the hello world of machine learning. It’s the simplest predictive modelling you can do, and it’s predictive because given an independent value x
you can then predict what the dependant value of y
will be. For example cricket chirps increase linearly with the independent variable temperature, so if the temperature is 70 degrees fahrenheit, then cricket chirps should be around 120 per minute, at least in Iowa in autumn where this data was collected.
It’s also predictive because you can extend the line beyond the data you have, you can extrapolate from the data. So you can use a value for x
that you have never seen before and have no data about to predict the value of cricket chirps per hour.
Equation
A line is represented by an equation y = a*x + b
.

y
is the value you’re trying to predict based on the value ofx

b
is the intercept of the line to they
axis. 
a
defines the slope of the line
x
is independent variable, y
is the dependant variable, the nature of the relationship is defined by the values a
and b
. To find the line that best represents a linear relationship between two sets of variables x
and y
we need to find values for a
and b
, we call this the best fit line.
Note
One reason for using linear regression as our first proper TensorFlow.js application is that the problem can be represented as a single neuron.
As long as we have some input data (x
) with known good values (y
) we can use TensorFlow.js to optimize (train) the values of a
and b
to find our best fit line.
The application we will be building in this chapter
We could demo this with a set of data such as temperature and cricket chirps, but I find it’s easier to understand what’s going on when you can play around with the data yourself, adjust, and see how this affects the training and outcome.
So in our demo app you will be making the data points yourself from your own clicks on the screen, you could just as easily load up your own data sourced from somewhere else though.
Every time you click on the screen, you add a data point and it a
and b
through 300 executions of optimizer.minimise
.
Advanced JavaScript
This unique course teaches you advanced JavaScript knowledge through a series of interview questions. Bring your JavaScript to the 2021's today.
[🌲,🌳,🌴].push(🌲)If you find my courses useful, please consider planting a tree on my behalf to combat climate change. Just $4.50 will pay for 25 trees to be planted in my name. Plant a tree!