What Machine Learning Practitioners Can Learn from Dog Trainers

Dog training is not rocket science, but it’s close to data science

Jordan Gomes
Towards Data Science

--

Meet Prada. Prada is the best dog ever — a beautiful, sweet, caring, really magnificent animal. A 10/10 good doggo.

Prada: a very good doggo (image by Kevin B.)

My friend rescued Prada a year ago now, and became passionate about dog training. Dog training — he explained to me — is a 2-step process. During the first step, you teach the good doggo the behavior you want. The second step is about linking this behavior to a certain trigger.

Achieving step #1 is all about repeating the behavior over and over again, rewarding the magnificent animal with praises and treats whenever they do it.

Achieving step #2 is a bit more complex. You want the dog to understand what signal should trigger the behavior you trained.

And to some extent, the process for step #2 is pretty similar to the way you’d train a model.

Using dog training to build an intuitive understanding of model training

Let’s imagine you just rescued a 10/10 good doggolito and you want to teach it to give its paw. You decide that, from now on, after your daily evening walk to the park, you’ll start training it. You start you first training sessions and start rewarding it every time it lifts its paw (to teach the behavior).

The first few training instances

After a few training instances, your doggo starts lifting its paw by itself! This is an excitement development — your animal now knows this behavior and associated the fact of lifting its paw with the praise. It is time to teach it to associate lifting its little paw to a verbal cue. Back to the classroom!

We’re getting there!

And after a few more training instances — now your dog is giving you its paw every time you use the verbal cue! You are super excited and you want to show this to all your friends.

You decide to organize a little gathering at your place, with some good snacks, some good music, and some good friends. After everyone arrives, you decide it is showtime. You crouch next to your doggo and say playfully “Give paw!” But your dog doesn’t move. You repeat the command again. Nothing happen.

You start sweating profusely. You try it again with a different voice, but nothing changes. You realize nothing will be happening at this point.

You are now the laughingstock of the group — which is exactly what Mike was waiting for. Since you publicly disagreed with its review of the movie “Everything Everywhere All at Once” at the restaurant the other day, he has been looking for a way to put you down, and clearly he has it now.

Dang — what happened?

Parsing the signal from the noise

What seemed to be ‘clear’ on your side, might have not been that clear on your doggo’s side. Because on its side — this is the input it received:

The input leading to the ‘Mike event’

And from this input, it was hard to understand that your verbal cue, with him performing the behavior he learned, was what was expected.

The lesson here is the following: if you want your dog to answer your cue in any location (at home, in the park, in the street), no matter the environment (whether there are people around or not), no matter the way you say it (whether you yell it, say it softly, or say it in a discussion with your partner), no matter your body language (whether you extend your hand or not) and no matter if you are the one saying the cue or someone else — you need to train it accordingly.

This is where a parallel can be drawn with Machine Learning and what we call generalization. You want your model to work in most situations, including in situation with previously unforeseen data. You want your model to understand the ‘true’ signal —and to not take into account the noise that is coming from either the individual variability of each observation or from random features that actually shouldn’t have any importance in the decision making process of the model.

In the example above, by training your dog in always the same controlled environment, it ended up using both the signal (vocal cue and behavior) and the noise (being in the park, you crouching, you using an assertive voice, etc.) to make its decision.

Your doggo overfitted to the training data, and as a result, it had a great performance in its training phase (because it fitted the training set so well it even fitted the noise) but it didn’t generalize the learning well — i.e. the verbal cue wasn’t working well in different settings.

What’s interesting about this parallel is that it also allows to build an intuitive understanding of how overfitting can happen (when you have a lot of different features that can end up confusing your model) and what can be some strategy to fix it (in this instance, train your doggo friend in different settings so that it gets better at distinguishing the noise from the signal).

But do we even know what the true signal is?

Your doggo now gives its paw every time — and sometimes as soon as you open your mouth. Which leaves you wondering — how can it be so fast? Did it develop some kind of intuitions of what you are going to say?

Maybe the answer is that what you believe to be the signal (the event of you using your vocal cue) is not. The real signal is the event of you wanting your dog to give its paw. And maybe there are some situations in which you commonly want that, or there are some tell-tale signs that you might be wanting that at a given moment — informations that your dog processed, learned, and is now able to use to make its predictions more accurate. From your perspective it is wonderful and magic — from your doggo’s perspective it is just repeated observations.

The interesting thing with Machine Learning (that you unfortunately don’t have with dog training) is that you have tools to see things from your model’s perspective. You have access to the training data, the evaluation metrics, the feature importance — and you can (in most cases / non-blackbox models) understand how the decisions were made.

It is slightly less magic for sure — but at least when your stakeholders ask you how it works and why it behave in the way it behaves, you can easily come up with an answer and ensure they end up using your work.

--

--

Head of LCS Analytics @Snap/ ex-YouTube. Analytics, Content, ML & everything in-between. Opinions are my own - https://analyticsexplained.substack.com