Rediscovering Math Through Machine Learning

There are two major, obvious, technology trends of interest to me that are being used to solve business problems today: blockchain and machine learning. The promise of AI has tantalized computer scientists and the general public for a long time, with general human intelligence out of grasp even still, however, modern advances in approaches to implementing machine learning algorithms coupled with a dramatic growth in computational capacity have yielded powerful tools to address discrete problem domains. What machine learning isn’t, is trying to build human-level general intelligence into machines. Instead, as the name connotes, it’s about creating programs that enable computers to use example data or past experience to solve a given, discrete, problem.

In order to pursue my interest in ML, I’m enrolled in Coursera’s machine learning course taught by Stanford Adjunct Professor of Computer Science, Andrew Ng. The course is intended to be accessible to relative lay-people without any meaningful background in linear algebra or formal computer science. Normally, hearing the words “linear algebra” would make my eyes glaze over, but the math involved in the course is simplified, indeed accessible, and mostly pertaining to matrix operations which is pretty straightforward anyhow.

What surprised me was how interesting the math was and how we could apply it to solve computational problems. I suppose this is the difference between theory and applied math and it was striking to see how powerful and efficient certain mathematical operations could be in solving otherwise iterative computational problems.

In the course, we start with supervised learning where we supply attributes and expected results—in other words, for each data sample, the “right answer” is provided. This presents a regression problem where we predict real-valued output based on the supplied training data. So, given a training set, a learning algorithm, we create a hypothesis () on the expected output based on a data point outside the sample, described by the following equation (when considering linear regression with a single variable/feature):

where and represent the training set parameters and represents the single feature input. In this form, this is a basic 1st-degree polynomial (linear) equation where is the y-intercept and is the slope.

Here’s an example data set of house size (x) to price (y) and the corresponding scatterplot:

sample house price data size to price correlates

What we’re trying to do is find the line that fits this data the best (linear regression). Using the equation above and what we know about 1st-degree polynomial equations, we can observe the following given certain values of and :

Where (y-intercept 0, slope 0.5): 0 + 0.5x

Where (y-intercept 1, slope 0.5): 1 + 0.5x

Now what we want to do with the sample housing data is fit a line do the data that minimizes the distance between the data points and the line describing our hypothesis. In other words, we want to choose and so that our is close to for our training examples so that we have something like this:

line fit

The “cost” of the hypothesis (our fitting equation) is the sum of the squared difference between the hypothesis (point on the line) and actual data point. So our goal is to determine the best values for and to minimize the cost, whereby we find the best fit for the training data and allowing us to confidently determine values outside of the training set.

We would therefore define the cost function as follows (where m is the number of sample data):

and our goal is to and we graph the costs for various values of . Let’s walk through an example where we assume all the data points are described by the function , basically the x-axis:

cost calculation

We’d calculate the cost as follows (using the differences between the expected and actual values and ignoring the constant term):

This represents a single value of which we graph along with various permutations of . Let’s do this for a few more examples of :

, we calculate the cost against a line with slope of .6. This means our values are and the cost calculated as follows:

, values are and the cost as follows:

, values are and the cost as follows:

For , the cost would obviously be 0.

As you can see, these points describe a parabola, on a graph with on the x-axis and on the y, with a global minima at , which is where the cost () of this function has been minimized.

When we graph the individual parameters and against , we get a contour plot/figure as follows:

contour plot

I’ll leave things at that for now and continue with the concept of gradient descent next time.

comments powered by Disqus