Das Video kommt von YouTube: erst beim Abspielen verbindet sich die Seite mit YouTube (Google).
Overfitting And Underfitting Machine Learning | Machine Learning Tutorial For Beginners |Simplilearn
Das Wichtigste aus dem Video
Tipp auf eine Zeit – das Video springt genau dorthin.
Transkriptautomatisch erstellt · 114 Zeilen
- hello everyone welcome to this video tutorial by simply learn in this video we will learn about overfitting and underfitting in machine learning we have
- our experience instructor richard who will take us through this video and help us understand the basics of overfitting and underfitting the reasons why it
- occurs and finally we look at a demo in python over to richard now what is overfitting
- what is underfitting and those are like the biggest things right now in data science is overfitting and under fitting what does that mean
- so let's go ahead and talk about overfitting when we talk about overfitting it's a scenario where the machine learning
- model tries to learn from the details along with the noise and the data tries to fit each data point on the curve you can see that
- um if you plug in your coordinates you're just going to get the whatever it's fitted every point on the data stream there's no average there's no
- two points that might have the you know y might have two different answers because if the wind blows a certain way um in
- the efficiency of your car maybe you have a headwind so your car might alter how efficient it is as it goes and so there's going to be this variance on
- here and this says no you can't have any variance with you know the this is it's going to be exactly this it can't be any you can't be the same speed or the same
- car and have a slightly different efficiency so as the model has very less flexibility it fails to predict new
- data points and thus the model rejects every new data point during the prediction so you'll get like a really high error
- on here and so reasons for overfitting data used for training is not cleaned
- and contains noise garbage values in it you can spend so much time cleaning your data and it's so important it's so important that if you have if you have
- some kind of something wrong with the data coming in it needs to be addressed whether it's a source of the data maybe they use in
- medical different measuring tools uh so you now have to adjust for data that came in from hospital a versus hospital b or even off of machine a and
- machine b that's testing something and those those numbers are coming in wrong the model has a high variance again wind is a good example i was
- talking about that with the car you may have a hundred tests but because the wind's blowing it's all over the place
- size of training data used is not enough so a small amount of data is going to also cause this problem you only have a few points and you try to plot
- everything the model is too complex this comes up a lot we put too many pieces together and how
- they interact can't even be tracked and so you have to go back back break it up and find out actually what correlates and what doesn't
- so what is underfitting a scenario where machine learning models can either learn
- the relationship between the data points nor predict or classify a new data point and you can see here we have our efficiency of our
- car and our line drawn and it's just going to be way off for both the training and the predicting data as the model doesn't fully learn the
- patterns it accepts every new data point during the prediction so instead of looking for a general pattern we just kind of accept
- everything data used for training is not cleaned and contains noise garbage and values again under fitting and overfitting same
- issue you've got to clean your data the model has a high bias we've seen this in all kinds of things from
- [Music] the mod the most common is the driving cars to facial identification or whatever it is the model itself when
- they build it might have a bias towards one thing and this would be an underfitted model would have that bias because it's averaged it out so if you
- have five people from india and 10 people from africa and 20 people from the u.s you
- created a bias because it's looking at the 20 people and you only have a small amount of data to work with
- size of training data used is not enough that goes with the size i was just talking about so we have a model with a high bias we
- have size of training data used it's not enough the model is too simple again this is one straight line through all the data when it needs a slight
- shift to it for other reasons so what is a good fit uh a linear curve that best fits the data is neither overfitting or under
- fitting models but is just right and of course we have the nice examples here where we have overfitting lines going up and down every point is trying
- to be include gluted underfitting the line really is off from where the data is and then a good fit is got to
- get rid of that minimize that error coming through so this is all exciting but what does this look like so we really need to jump
- in and put a code together and see what this looks like when we're programming for this demo we'll bring up our trusty anaconda and go into jupiter notebook
- for python move myself out of the way here uh and so we're going to start off this
- is going to be a demo on overfitting and underfitting using python and let's start with our imports now if you've been through enough of
- these tutorials we don't want to spend a huge amount of time on what we're bringing in and what we're doing so you should be up on doing this with
- python and how to bring in your different modules we're going to bring in the sklearn or the scikit processing sk
- learn dot neural network import in a mlp regressor so there's our regressor model right there
- that's going to be our linear regression model and we have our metrics mean absolute error if you remember we had our that's
- how we figure out how well it fits is how far off that error is based on the um mean square error value mse
- and then of course numpy because we just like to work with numpy it's a great data array we always import it as mp that's the most common way of doing it
- and then we have sklearn model selection import validation curve so we're going to look at a validation curve to see how good our models are
- and then we have the data set we'll use the very famous iris data set and that's embedded in the scikit so the s key
- learn data sets have a load iris in there and then we have the matplot library because if you're doing any kind of demo
- or showing this off to your shareholders we want to have something nice to display it on and then we have sklearn model selection
- we're going to import import k-fold and we'll talk about that when we get to it and then we're going to go ahead and do just for our numpy we're going to do
- like a random seed for random numbers and then for our plot style we'll use the gg plot that's just some back end setup you could even probably leave the
- plot style out depending on what version of you're using of depending on what version you're using a
- map plot library and then we'll go ahead and run this it's not going to do anything that we can visibly see because it's just
- loading those modules and then we also want to load our iris data in here and the iris data has an iris data and iris target
- we're going to load that as x and y and just so you can have an idea what we're talking about we're going to go ahead and print
- x and just the first bit of x we'll just do the top of x and we'll also print y so you can see
- what the top of y looks like print y and since we're a numpy we're going to go ahead and do our own thing if this
- was of course pandas we could just do the head of it and see what it looks like and you can see here we've loaded this
- up and in x we have these different measurements that they take of the flower the iris flowers from this particular data set
- and what kind of flower it is it's going to be a zero one or a two is actually what the target comes out of even though that doesn't show in here
- and so we're going to come in here and we're going to use the k folds cross validation with 20 folds and a good catch that this was a model
- selection we're we're going through and we're selecting different parts of the data in here here
- we use k-fold cross validation with 20 folds k equals 20 to evaluate the generalization efficiency of the model within each fold we will then estimate
- the training and test error using the training and test sets respectfully so here we have our kf equals kf k fold here's our splits on the top
- and then we need to go ahead and have our list training error we're going to create an array for that we're going to list our testing error
- and for train index and test index in k f dot split x x train y uh x train and x test we're going to go ahead and split up our
- our data our x values and the same thing with the y values so now we have an x train and x test a y train and a y test and then here's our model our impel
- mlp regressor and that's your linear regression model in there and we have used a multi-layer perceptron mlp
- so this is a neural network multi-layer perceptron that's what the mlp is for regressor means that it is dealing with
- numbers we're not categorizing things um and then let's go ahead uh i kind of went off the screen here we'll just go
- ahead and bring that down it's a class of feed forward artificial neural networks and they kind of loosely call it a and n
- don't get caught up in the a n n n and n m n n there's nnn is neural network and then everybody
- puts their own flavor on it depending on what they're doing uh so if you see the nnn you know you're dealing with a neural network
- so we go ahead and fit our data here's our model dot fit we have x train and y train and the y train data we're going to
- predict equals model dot predict x train so here's our prediction of what it's going to be so we've trained it and we've predicted it we've trained our the
- train data and then we have our y train and then we have our y test and the y test equals a model predict x test
- now notice what we did here is we're going to use our model to predict what we think y should be but this is the training set
- uh so we've trained it with this data and now we want to see how good our model fits our training data and then we want to see how well it fits
- our testing data so we take our fold training error mean absolute error y train y train data predict and we're gonna do
- our full testing error the mean absolute error of y test and y test data predict and we do this and here's our mean
- absolute error there's our a little bit different connotation but that's that's taking the square value and finding the in this case it's using
- the absolute value so instead of the square value we get rid of the minus and pluses by using an absolute value and we find the average of that and that works
- the same way as doing the squared value and then we take our list training error and we're going to just append it for each
- each one of these runs we go through so every time we fold the data think of it like this we want to go ahead and take a piece of
- data that's going to be one piece of the data and we're going to look at each section and we want to go through each section to see how well it does and
- splits it up this way we have a nice picture uh when we're looking at it from a distance i do this a lot when i do x and tr when
- i split my x train and my y train i'll take two thirds of the data and then one third of the data and then i'll switch it and i'll do three different models so
- i can really see how well it tests out and how that averages out this is the same thing but with the with the k fold we're doing and we're
- doing it across 20 sections we'll go ahead and run this and we run this it's not too exciting because we're just loading up the data
- and appending it into our list and so we want to take with this is we're going to go ahead and plot it
- and this is where we can really see what's going on this is where it gets exciting uh so we take it we're going to create a couple subplots uh that way we
- have a nice setup down here we're splitting it up into a couple different graphs
- and let's go ahead and run this and then we'll walk through it a little bit so our subplot comes in
- there's our subplot and then our plt plot we're going to do in there range one we're going ahead and do the splits plus one npra list training error uh
- ravel this is of course just a code to how we properly set it up on there so that it sees it correctly
- and then we have our x label which is our number fold uh plot the y label training error plot the title training area across folds
- plot the tight layout plot the subplot so we're going to move on to this is one two one one two two there's our one it's just one and two
- uh it has to do with how it how it layers it on there for doing multiple plots because you can do all kinds of cool things with our plot our pi plot
- library uh and again we're going to go ahead and do the same thing for the error and we end up with our training error across
- folds and our testing area across folds and so you can see these different folds how they kind of spike and how they look and so we're talking about overfitting
- or under fitting we're comparing these two graphs and if one of them is more off than the other one
- if you're looking at these two graphs you're going to say hey is this one overfit or underfit and this is always a good question to ask i mean what do we
- got going here is that over fit or is that underfit and i would say based on these two graphs and the
- training data uh the training data is more sporadic than the testing data so i would look at this and say hey
- this might need to be fit a little bit better maybe we don't have enough data with the iris we probably don't
- something else is going on here so it's a little underfit maybe a different model would fit better i would not use a neural network model for this i would
- actually use just a basic linear linear model on this a lot of different choices but this gives you an idea what we're
- looking at is how chaotic are these two is it getting better or is it getting worse if at some point the training data gets
- so much better than the testing data you know you've over fit it and that's where you start running into the overfitting this to me looks like it's under fit
- so that concludes underfitting and overfitting thank you for watching this video i hope it was useful and informative if you
- liked this video then please go ahead and subscribe to simply learn channel to stay updated with all the latest trending technologies stay tuned for
- more from simply learn [Music] hi there if you like this video
- subscribe to the simply learn youtube channel and click here to watch similar videos turn it up and get certified click here
Zum Nachlesen
Verzerrung-Varianz-DilemmaK-nächste Nachbarn. Bearbeiten. Im Falle des k-nächste-Nachbarn-Algorithmus existiert eine geschlossene Formel, die die Verzerrung-Varianz-Zerlegung in …
Überwachtes LernenÜberwachtes Lernen (englisch supervised learning) ist eine wichtige Kategorie des Maschinellen Lernens. Dabei wird ein Lernalgorithmus mit Datensätzen …
BestimmtheitsmaßDas Bestimmtheitsmaß gibt allerdings nur Auskunft über die Stärke des Zusammenhangs, nicht über Kausalität. Das Bestimmtheitsmaß zeigt zwar die „Qualität …
RegressionsanalyseDie Regressionsanalyse ist ein Instrumentarium statistischer Analyseverfahren, die zum Ziel haben, Beziehungen zwischen einer abhängigen (auch erklärte …