Machine Learning & Finding What You Seek

This is one of a series of posts that covers machine learning and its applications. The goal is to discuss the similarities between human and machine learning processes—and to use this understanding to think productively about wins and losses in any endeavor or sphere of life. We will start with talking about how exactly machine “learning” actually learns. I have mostly removed all jargon, and I’ve replaced it with everyday language as these concepts are truly accessible to anyone like this. If you find this post interesting or helpful, do check out the rest of the series.

One note: I use the words algorithm and model a fair bit below. You can think of the algorithm as the procedure used to approach a learning task. The model is the trained state of the algorithm after it works through some training data. A model potentially gets updated in some way each time the algorithm gets new data to learn from. The model is the sum total of the algorithm’s current learning towards the task at hand.

Similar to a human mind without experience, a machine-learning algorithm without training data to learn from is not very useful.

You Be The Machine

To start, I’m going to give you a very quick learning task that is something we might ask a computer to work on. I will have you work on classification of images. Are you ready? You’ve got this! First your training dataset:

A simple training dataset from which an ML algorithm can learn

Pretend you are the computer. You are given a set of 8 training images each with a label. Look at each of the images as if you’ve never seen these things before; try to learn what a cat is and what a dog is. Note that one good thing about this dataset is that we are teaching the computer that cats and dogs come in a variety of colors/patterns and that these aren’t the defining aspects of the thing. In training a real model, we might give the computer 50 to 50,000 examples of each instead of 4 each, but you get the idea. Now that you have trained yourself on these 8 images, I have a question for you: what are the things in each of the following two images? Before you answer based on your years of lived experience, I want you to attempt to answer as if the only training you have on dogs and cats is the above 8 images.

If you answered “dog” for the first one, great! You have earned your keep as a machine learning algorithm. If you answered “dog” for the second one, I think there’s a chance you cheated and used your life experience instead of just the training data! Look again, and you’ll clearly see that in some ways, the second image looks more like the 4 cats in the training images above. In the training data, all the cats have ears that stand up, they are all sitting upright, and each of the pictures shows their whole body including legs. But each of our training images for the dogs shows just a dog face—no legs, no body.

If you answered “cat” for the second image, I would say that you did your job just fine and there’s nothing wrong with you as a machine learning algorithm. What’s wrong is the fact that our training dataset was very small and lopsided—and thus it biased you, the machine, to think that any furry creature sitting down on its hind legs with pointy ears is a cat. Given that the face in the second image is definitely more doglike than catlike, the model could also be inconclusive saying something like “30% chance of dog, 60% chance of cat, 10% neither.” The facial structure has it thinking it’s somewhat doglike, but the ears and the pose has it thinking more catlike.

Before reading on, I have a question for you: what can you do without writing a line of code to get the algorithm working better to identify cats and dogs in a variety of positions, angles, etc.?

More Data is Good, Diverse Data is Better

You have now learned one of the first pitfalls of machine learning: an algorithm’s ability to label things or predict things is only as good as the training data it is fed. This is honestly true of human learning as well. If you are only exposed to a small slice of the world’s people or the world’s geography, your ability to understand and transfer what you’ve learned to people and places outside of your slice is limited.

Whenever I’m working with a machine learning algorithm, I tend to be exceptionally interested in the nature of the mistakes that it makes. I don’t spend a lot of time celebrating the 95% of things that it handled correctly; I spend my time looking closely at the 5% of things it got wrong, and I think through the main ways I might improve the machine’s performance so that it makes fewer mistakes:

  1. Change the algorithm(s) used.
  2. Work on ways to code some hints to give the algorithm a leg up on understanding the data—essentially formulas that give it some of the human understanding we have. These hints are called features, and this creative coding work is called “feature engineering.”
  3. Work on gathering a larger and more diverse training dataset.

The first two of these are beyond the scope of this article and get a bit technical, but the third one is easy to understand. If we were to give the machine 100 images labeled as cats and 100 images labeled as dogs, it would almost certainly be more skilled at classification than it is with 4 of each. That said, if I still only provide training examples of cats sitting on hind legs and only have dogs’ faces instead of their whole bodies, my algorithm remains limited in its experience and is still limited in its ability to generalize what it has “learned” to a wider variety of situations. It’ll only be truly good at differentiating between sitting cats and the faces of dogs. It would be a more accurate classifier if trained on a reasonably wide set of animal positions, breeds, and backgrounds. Even if I only have time to give it a handful more dog images and cat images, it’ll learn the most and improve the most if those new images added to the training data are diverse. To learn more about AI that struggles in situations outside of its training, see this article on tricks that can beat the best Go-playing AI algorithms.

Admittedly most readers are more likely to be interested in using AI to rank potential customers or classify data in databases rather than classifying images of pets. The principles are the same, however, and building a diverse training set will be important for any business use of machine learning.

Getting philosophical on finding what you seek

In machine learning, it turns out that the most valuable training examples are those that are confusing or are outright surprises to the algorithm when it first sees them. To use human language, most algorithms seek to minimize the “cognitive dissonance” the model “feels” with regards to new confusing cases. The technical term for this is “minimizing the loss” but essentially you can think of it like this: the model changes most when it encounters a training example that is most surprising or most contrary to its current model of the task at hand. It changes significantly in order to ensure it would have a higher chance of success next time if presented with a similar image and asked to classify it.

If you train the algorithm on an additional 100 cat pictures and for all 100 it would have already known they were cats, it might improve just a bit in its abilities but not remarkably. If instead you give it just 20 additional cat pictures and 5 of them were surprises where the algorithm would have initially said, “not a cat,” this additional training data or experience is very impactful and will improve the accuracy of the model significantly—or at least it’ll decrease the model’s overconfidence.

The same is true in life. Your understanding of the world is most improved by new information that you didn’t expect, and it only improves slowly when given additional information that already squares with your understanding of the world. This is why scientists often say that they long for surprises in their experimental data. Data that goes exactly opposite your working model forces you to think and learn a lot more than data that confirms what you already think.

Binary Classification—and when “no” leads to “yes”

Whether it comes to finding the right person to hire, the right next job, the winning needles in a haystack of data, it turns out that closed doors, failures, and mistakes are exceptionally valuable. It turns out that the “nos” in life are the key to the next “yes.” It’s not just a cliche: closed doors are key to finding the open ones and failure truly is only failure if you fail to learn from it.

I was recently working on a machine learning model that does binary classification, which is a fancy way of saying that it looks at a spreadsheet and for each row it tries to figure out if it’s a “yes” or a “no” based on what it has learned from other rows that are known to be “yeses” or “nos”. The model was working better than I had initially hoped, and it was identifying needles in a very large haystack of data that experts were missing with traditional non-ML search and labeling algorithms. I was thrilled that it was working so well, and I then decided to see how it would do labeling on a slightly wider set of real-world data. Since I was also working on creating a training dataset from scratch, I would manually review its predictions on new examples; upon manual review, I would add it to the training dataset with the confirmed label.

Right after I started throwing a wider set of data at it, it was performing absolutely horribly and was mislabeling things constantly. I had asked it to extrapolate only slightly outside of the training dataset, so I thought it would be no big deal, but it was. I manually reviewed perhaps 40 examples in a row that it thought were in the “yes” category but all of them were actually “no.” I started looking at my code to see it I had somehow broken it—after all, it had been working quite well the day before.

It turns out that nothing was broken. I stuck with it and kept saying, “actually that’s a no” to heaps of things that it was labeling as a “yes.” The model started to learn. The next day it was back to finding needles in a haystack with great success. It was only then that I realized that the key to getting back to winning was a whole bunch of mistakes that I fed back into the system so it would learn from them.

Getting started

Whether you are trying to see if machine learning can transform your work, or just reading for the purpose of growing your data skills, be encouraged that the each “no” in life and in machine learning will help you clarify where to be looking for the next “yes.” If you want some consulting as you get started with machine learning, you want a complete outsourced solution for it, or even if you just want to ask questions to see if there is potential return on investment from machine learning in your line of work, then answer is certainly “yes”—I’d love to talk. Set up a time today.

Admittedly, image classification or distinguishing between cat pictures and dog pictures is probably not a critical goal for your work. There are so many other things that machine learning can do well, and in many business applications the examples being learned and later predicted are actually rows from a spreadsheet or a database. See this earlier post for a wider explanation of the types of tasks ML can do well.

Peter VanWylen

Peter VanWylen loves data and enjoys helping people attain their goals with the right tools for data gathering, analysis, dashboards, and data science.