6.11 Machine Learning development process | Error analysis --[ML | Andrew Ng]
 In terms of the most important ways to help you run diagnostics to choose what to try next to improve your learning algorithm performance, I would say bias invariance is probably the most important idea and error analysis would probably be second on my list. So let's take a look at what this means. Concretely, let's say you have MCV equals 500 cross-validation examples and your algorithm misclassifies 100 of these 500 cross-validating examples. The error analysis process just refers to manually looking through these 100 examples and trying to gain insights into where the algorithm is going wrong. Specifically, what I would often do is find a set of examples that the algorithm has misclassified examples from the cross-validation set and try to group them into common themes or common properties or common traits. So for example, if you notice that quite a lot of the misclassified spam emails are pharmaceutical sales, trying to sell medicines or drugs, then I would actually go through these examples and count up by hand how many emails are misclassified are pharmaceutical spam and say there are 21 emails that are pharmaceutical spam. Or if you suspect that deliberate misspellings may be tripping up your spam classifier, then I would also go through and just count up how many of these examples that it misclassified had a deliberate misspelling. Let's say I find three out of 100. Or looking through the email routing info, I find seven has unusual email routing and 18 emails trying to steal passwords or phishing emails. Spam is sometimes also instead of writing the spam message in the email body, they instead create an image and then write the spammy message inside an image that appears in the email. It's a bit harder for learning algorithm to figure out what's going on. And so maybe some of those emails are these embedded image spam. If you end up with these counts, then that tells you that pharmaceutical spam and emails trying to steal passwords or phishing emails seem to be huge problems. Whereas deliberate misspellings, well, it is a problem. It is a smaller one. In particular, what this analysis tells you is that even if you were to build really sophisticated algorithms to find deliberate misspellings, it would only solve three out of 100 of your misclassified examples. So the net impact seems like it may not be that large. Doesn't mean it's not worth doing, but when you're prioritizing what to do, you might therefore decide not to prioritize this as highly. And by the way, I'm telling the story because I once actually spent a lot of time building algorithms to find deliberate misspellings in spam emails only much later to realize that the net impact was actually quite small. So this is one example where I wish I had done a more careful error analysis before spending a lot of time myself trying to find these deliberate misspellings. Just a couple of notes on this process. These categories can be overlapping or in other words, they're not mutually exclusive. So for example, there can be a pharmaceutical spam email that also has unusual routing or a password that has deliberate misspellings and is also trying to carry out a phishing attack. So one email can be counted in multiple categories. And in this example, I had said that the algorithm misclassifies 100 examples and will look at 100 examples manually. If you have a larger cross validation set, say we had 5,000 cross validation examples, and if the algorithm misclassified, say 1,000 of them, then you may not have the time, depending on the team size and how much time you have to work on this project, you may not have the time to manually look at all 1,000 examples that the algorithm misclassifies. In that case, I will often sample randomly a subset of usually around 100, maybe a couple of hundred examples, because that's the amount that you can look through in a reasonable amount of time. And hopefully looking through maybe around 100 examples will give you enough statistics about what are the most common types of errors and therefore where may be most fruitful to focus your attention. And so after this analysis, if you find that a lot of errors are pharmaceutical spam emails, then this might give you some ideas or inspiration for things to do next. For example, you may decide to collect more data, but not more data of everything, but just try to find more data of pharmaceutical spam emails so that the learning algorithm can do a better job recognizing these pharmaceutical spams. Or you may decide to come up with some new features that are related to say specific names of drugs or specific names of pharmaceutical products that the spammers are trying to sell in order to help your learning algorithm become better at recognizing this type of pharma spam. Then again, this might inspire you to make specific changes to the algorithm relating to detecting phishing emails. For example, you might look at the URLs in the email and write special code to come up with extra features to see this linking to suspicious URLs. Or again, you may decide to get more data of phishing emails specifically in order to help your learning algorithm do a better job at recognizing them. So the point of this error analysis is by manually examining a set of examples that your algorithm is misclassifying or mislabeling. And this will create inspiration for what might be useful to try next. And sometimes it can also tell you that certain types of errors are sufficiently rare, that they aren't worth as much of your time to try to fix. And so returning to this list, a bias-variance analysis should tell you if collecting more data is helpful or not. Based on our error analysis in the example we just went through, it looks like more sophisticated email features could help, but only a bit. Whereas more sophisticated features to detect pharmas spam or phishing emails could help a lot. And this detecting misspellings would not help nearly as much. So in general, I've found both the bias-variance diagnostic as well as carrying out this form of error analysis to be really helpful to screening or to deciding which changes to the model are more promising to try out next. Now one limitation of error analysis is that it's much easier to do for problems that humans are good at. So you can look at an email and say, you think it's a spam email, why did the algorithm get it wrong? Error analysis can be a bit harder for tasks that even humans aren't good at. For example, if you're trying to predict what ads someone will click on on a website, well, I can't predict what someone will click on, so error analysis there actually tends to be more difficult. But when you apply error analysis to problems that you can, it can be extremely helpful for focusing attention on the more promising things to try. And that in turn can easily save you months of otherwise fruitless work. In the next video, I'd like to dive deeper into the problem of adding data. When you train a learning algorithm, sometimes you decide there's high variance and you want to get more data for it. And there's some techniques that can make how you add data much more efficient. So let's take a look at that so that hopefully you'll be armed with some good ways to get more data for your learning application.
[{"start": 0.0, "end": 7.5200000000000005, "text": " In terms of the most important ways to help you run diagnostics to choose what to try"}, {"start": 7.5200000000000005, "end": 12.76, "text": " next to improve your learning algorithm performance, I would say bias invariance is probably the"}, {"start": 12.76, "end": 17.36, "text": " most important idea and error analysis would probably be second on my list."}, {"start": 17.36, "end": 19.68, "text": " So let's take a look at what this means."}, {"start": 19.68, "end": 27.96, "text": " Concretely, let's say you have MCV equals 500 cross-validation examples and your algorithm"}, {"start": 27.96, "end": 33.08, "text": " misclassifies 100 of these 500 cross-validating examples."}, {"start": 33.08, "end": 40.52, "text": " The error analysis process just refers to manually looking through these 100 examples"}, {"start": 40.52, "end": 45.480000000000004, "text": " and trying to gain insights into where the algorithm is going wrong."}, {"start": 45.480000000000004, "end": 53.92, "text": " Specifically, what I would often do is find a set of examples that the algorithm has misclassified"}, {"start": 53.92, "end": 60.56, "text": " examples from the cross-validation set and try to group them into common themes or common"}, {"start": 60.56, "end": 63.2, "text": " properties or common traits."}, {"start": 63.2, "end": 70.0, "text": " So for example, if you notice that quite a lot of the misclassified spam emails are pharmaceutical"}, {"start": 70.0, "end": 75.6, "text": " sales, trying to sell medicines or drugs, then I would actually go through these examples"}, {"start": 75.6, "end": 82.56, "text": " and count up by hand how many emails are misclassified are pharmaceutical spam and say there are"}, {"start": 82.56, "end": 86.0, "text": " 21 emails that are pharmaceutical spam."}, {"start": 86.0, "end": 93.36, "text": " Or if you suspect that deliberate misspellings may be tripping up your spam classifier, then"}, {"start": 93.36, "end": 99.52000000000001, "text": " I would also go through and just count up how many of these examples that it misclassified"}, {"start": 99.52000000000001, "end": 101.2, "text": " had a deliberate misspelling."}, {"start": 101.2, "end": 104.28, "text": " Let's say I find three out of 100."}, {"start": 104.28, "end": 112.56, "text": " Or looking through the email routing info, I find seven has unusual email routing and"}, {"start": 112.56, "end": 118.36, "text": " 18 emails trying to steal passwords or phishing emails."}, {"start": 118.36, "end": 124.84, "text": " Spam is sometimes also instead of writing the spam message in the email body, they instead"}, {"start": 124.84, "end": 131.0, "text": " create an image and then write the spammy message inside an image that appears in the"}, {"start": 131.0, "end": 132.0, "text": " email."}, {"start": 132.0, "end": 134.8, "text": " It's a bit harder for learning algorithm to figure out what's going on."}, {"start": 134.8, "end": 139.96, "text": " And so maybe some of those emails are these embedded image spam."}, {"start": 139.96, "end": 148.88, "text": " If you end up with these counts, then that tells you that pharmaceutical spam and emails"}, {"start": 148.88, "end": 154.4, "text": " trying to steal passwords or phishing emails seem to be huge problems."}, {"start": 154.4, "end": 158.12, "text": " Whereas deliberate misspellings, well, it is a problem."}, {"start": 158.12, "end": 159.84, "text": " It is a smaller one."}, {"start": 159.84, "end": 165.72, "text": " In particular, what this analysis tells you is that even if you were to build really sophisticated"}, {"start": 165.72, "end": 172.84, "text": " algorithms to find deliberate misspellings, it would only solve three out of 100 of your"}, {"start": 172.84, "end": 174.6, "text": " misclassified examples."}, {"start": 174.6, "end": 178.76, "text": " So the net impact seems like it may not be that large."}, {"start": 178.76, "end": 183.38, "text": " Doesn't mean it's not worth doing, but when you're prioritizing what to do, you might"}, {"start": 183.38, "end": 186.92000000000002, "text": " therefore decide not to prioritize this as highly."}, {"start": 186.92, "end": 191.95999999999998, "text": " And by the way, I'm telling the story because I once actually spent a lot of time building"}, {"start": 191.95999999999998, "end": 197.07999999999998, "text": " algorithms to find deliberate misspellings in spam emails only much later to realize"}, {"start": 197.07999999999998, "end": 199.64, "text": " that the net impact was actually quite small."}, {"start": 199.64, "end": 204.04, "text": " So this is one example where I wish I had done a more careful error analysis before"}, {"start": 204.04, "end": 209.6, "text": " spending a lot of time myself trying to find these deliberate misspellings."}, {"start": 209.6, "end": 212.6, "text": " Just a couple of notes on this process."}, {"start": 212.6, "end": 218.92, "text": " These categories can be overlapping or in other words, they're not mutually exclusive."}, {"start": 218.92, "end": 226.2, "text": " So for example, there can be a pharmaceutical spam email that also has unusual routing or"}, {"start": 226.2, "end": 231.92, "text": " a password that has deliberate misspellings and is also trying to carry out a phishing"}, {"start": 231.92, "end": 233.06, "text": " attack."}, {"start": 233.06, "end": 237.51999999999998, "text": " So one email can be counted in multiple categories."}, {"start": 237.52, "end": 243.44, "text": " And in this example, I had said that the algorithm misclassifies 100 examples and will look at"}, {"start": 243.44, "end": 246.32000000000002, "text": " 100 examples manually."}, {"start": 246.32000000000002, "end": 252.88, "text": " If you have a larger cross validation set, say we had 5,000 cross validation examples,"}, {"start": 252.88, "end": 259.84000000000003, "text": " and if the algorithm misclassified, say 1,000 of them, then you may not have the time, depending"}, {"start": 259.84000000000003, "end": 265.12, "text": " on the team size and how much time you have to work on this project, you may not have"}, {"start": 265.12, "end": 270.6, "text": " the time to manually look at all 1,000 examples that the algorithm misclassifies."}, {"start": 270.6, "end": 277.04, "text": " In that case, I will often sample randomly a subset of usually around 100, maybe a couple"}, {"start": 277.04, "end": 280.72, "text": " of hundred examples, because that's the amount that you can look through in a reasonable"}, {"start": 280.72, "end": 282.48, "text": " amount of time."}, {"start": 282.48, "end": 287.2, "text": " And hopefully looking through maybe around 100 examples will give you enough statistics"}, {"start": 287.2, "end": 292.28000000000003, "text": " about what are the most common types of errors and therefore where may be most fruitful to"}, {"start": 292.28000000000003, "end": 294.64, "text": " focus your attention."}, {"start": 294.64, "end": 302.56, "text": " And so after this analysis, if you find that a lot of errors are pharmaceutical spam emails,"}, {"start": 302.56, "end": 308.64, "text": " then this might give you some ideas or inspiration for things to do next."}, {"start": 308.64, "end": 316.12, "text": " For example, you may decide to collect more data, but not more data of everything, but"}, {"start": 316.12, "end": 321.47999999999996, "text": " just try to find more data of pharmaceutical spam emails so that the learning algorithm"}, {"start": 321.48, "end": 325.8, "text": " can do a better job recognizing these pharmaceutical spams."}, {"start": 325.8, "end": 330.76, "text": " Or you may decide to come up with some new features that are related to say specific"}, {"start": 330.76, "end": 336.28000000000003, "text": " names of drugs or specific names of pharmaceutical products that the spammers are trying to sell"}, {"start": 336.28000000000003, "end": 341.20000000000005, "text": " in order to help your learning algorithm become better at recognizing this type of pharma"}, {"start": 341.20000000000005, "end": 342.20000000000005, "text": " spam."}, {"start": 342.20000000000005, "end": 348.36, "text": " Then again, this might inspire you to make specific changes to the algorithm relating"}, {"start": 348.36, "end": 350.32, "text": " to detecting phishing emails."}, {"start": 350.32, "end": 355.48, "text": " For example, you might look at the URLs in the email and write special code to come up"}, {"start": 355.48, "end": 359.24, "text": " with extra features to see this linking to suspicious URLs."}, {"start": 359.24, "end": 364.32, "text": " Or again, you may decide to get more data of phishing emails specifically in order to"}, {"start": 364.32, "end": 367.8, "text": " help your learning algorithm do a better job at recognizing them."}, {"start": 367.8, "end": 374.28, "text": " So the point of this error analysis is by manually examining a set of examples that"}, {"start": 374.28, "end": 378.2, "text": " your algorithm is misclassifying or mislabeling."}, {"start": 378.2, "end": 383.88, "text": " And this will create inspiration for what might be useful to try next."}, {"start": 383.88, "end": 390.32, "text": " And sometimes it can also tell you that certain types of errors are sufficiently rare, that"}, {"start": 390.32, "end": 394.2, "text": " they aren't worth as much of your time to try to fix."}, {"start": 394.2, "end": 400.08, "text": " And so returning to this list, a bias-variance analysis should tell you if collecting more"}, {"start": 400.08, "end": 402.84, "text": " data is helpful or not."}, {"start": 402.84, "end": 407.03999999999996, "text": " Based on our error analysis in the example we just went through, it looks like more sophisticated"}, {"start": 407.04, "end": 410.36, "text": " email features could help, but only a bit."}, {"start": 410.36, "end": 415.04, "text": " Whereas more sophisticated features to detect pharmas spam or phishing emails could help"}, {"start": 415.04, "end": 416.04, "text": " a lot."}, {"start": 416.04, "end": 420.36, "text": " And this detecting misspellings would not help nearly as much."}, {"start": 420.36, "end": 425.12, "text": " So in general, I've found both the bias-variance diagnostic as well as carrying out this form"}, {"start": 425.12, "end": 431.40000000000003, "text": " of error analysis to be really helpful to screening or to deciding which changes to"}, {"start": 431.40000000000003, "end": 434.40000000000003, "text": " the model are more promising to try out next."}, {"start": 434.4, "end": 440.32, "text": " Now one limitation of error analysis is that it's much easier to do for problems that humans"}, {"start": 440.32, "end": 441.32, "text": " are good at."}, {"start": 441.32, "end": 445.96, "text": " So you can look at an email and say, you think it's a spam email, why did the algorithm get"}, {"start": 445.96, "end": 446.96, "text": " it wrong?"}, {"start": 446.96, "end": 451.2, "text": " Error analysis can be a bit harder for tasks that even humans aren't good at."}, {"start": 451.2, "end": 455.91999999999996, "text": " For example, if you're trying to predict what ads someone will click on on a website, well,"}, {"start": 455.91999999999996, "end": 459.96, "text": " I can't predict what someone will click on, so error analysis there actually tends to"}, {"start": 459.96, "end": 461.5, "text": " be more difficult."}, {"start": 461.5, "end": 467.0, "text": " But when you apply error analysis to problems that you can, it can be extremely helpful"}, {"start": 467.0, "end": 470.36, "text": " for focusing attention on the more promising things to try."}, {"start": 470.36, "end": 475.8, "text": " And that in turn can easily save you months of otherwise fruitless work."}, {"start": 475.8, "end": 482.24, "text": " In the next video, I'd like to dive deeper into the problem of adding data."}, {"start": 482.24, "end": 486.62, "text": " When you train a learning algorithm, sometimes you decide there's high variance and you want"}, {"start": 486.62, "end": 488.82, "text": " to get more data for it."}, {"start": 488.82, "end": 493.44, "text": " And there's some techniques that can make how you add data much more efficient."}, {"start": 493.44, "end": 498.36, "text": " So let's take a look at that so that hopefully you'll be armed with some good ways to get"}, {"start": 498.36, "end": 519.4, "text": " more data for your learning application."}]