Term Overview: Generative vs Discriminative
In this lesson, we're going to walk through two terms that can be a little bit confusing if you've never heard them before and they are generative and discriminative algorithms and so these are two different types of algorithms that pretty much every algorithm that you're going to work with will fit in in some way or another.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

So let's look at generative models first and what these type of algorithms do is they model the distribution of the individual classes.

large

So imagine that you're building a handwriting recognition system. And so the way that a generative model would work is it would go and it would create a model for every single letter in the alphabet for every number and then it would store that model and then every single time it received a new input. So it wanted to see what the handwriting represented. It would then go and cross-reference it against its historical model set. And so that is at a very high level the way a generative model would work.

large

Now a discriminative model and this is what typically you're going to be implementing unless you're getting into neural networks and those kinds of things the discriminative model learns the hard or soft boundaries between classes. And so where as the generative model builds a entire model for every class in the system a discriminant model simply tries to find the key differences between each element.

And so some case studies on this a neural network is a very popular use case for generative models and if you remember back to when we walk through the example on how we could use a neural network to build out a tool for a baseball organization?

large

That allowed us to create all of these kinds of models such as pitch types, pitch locations, field dimensions, all of these kinds of elements. And so the way that generative system would work is it would take in all the historical data and then it would build its classes from there just like in the earlier example where we talked about the handwriting recognition tool and then from there any new elements that we needed to generate a prediction from would then go and run through all of those predefined and pre generated classes and that's really the genesis of the name generative, comes from the fact that the system is generating those classes it's storing them and then it's able to use those to make predictions.

Now when we look at an example of a discriminative algorithm. One of the best examples of this is a support vector machine.

large

Remember if you go back to the definition a discriminative algorithm looks for the boundaries between data points and so instead of going and creating this entire model for every class in the system. Instead what it does is it goes and it simply tries to find the boundaries. We can use the same exact use case we can come in right here we have an example of a system that performs handwriting recognition instead of creating a model for what a 1 looks like and what a 9 looks like. Instead what a support vector machine does is it simply tries to find the best boundaries that separate a 1 from a 9. And so that's exactly how it determines success.

So it will classify by seeing all of these 1s all of these 9s finding the key differences and then that is how it sets, in the support vector case machine, it sets its hyperplane it sets its differentiation point right there and coming back to the handwriting example if we get a new number that it's trying to recognize it is not going to look at all of the 9s and then all of the 1s.

It's simply going to look at the components inside of that new element and it's going to look at the boundary that set up and then depending on the components inside of the new element it's going to say okay it looks like based on where the pixels are located on the image it appears that you are a 1 or a 9.

But it's all based on where it falls on relation to the graph and where it falls in relation to these boundaries that have been set up. And so those are the key differences between discriminative algorithms and generative ones.