6.10 Machine Learning development process | Iterative loop of ML development --[ML | Andrew Ng]
 In the next few videos, I'd like to share with you what it's like to go through the process of developing a machine learning system so that when you are doing so yourself, hopefully you'll be in a position to make great decisions at many stages of the machine learning development process. Let's take a look first at the iterative loop of machine learning development. This is what developing a machine learning model will often feel like. First, you decide on what is the overall architecture of your system. And that means choosing your machine learning model as well as deciding what data to use, maybe picking the hyperparameters and so on. Then, given those decisions, you would implement and train a model. And as I've mentioned before, when you train a model for the first time, it will almost never work as well as you want it to. The next step that I recommend then is to implement or to look at a few diagnostics, such as looking at the bias and variance of your algorithm, as well as something we'll see in the next video called error analysis. And based on the insights from the diagnostics, you can then make decisions like, do you want to make your neural network bigger or change the lambda regularization parameter or maybe add more data or add more features or subtract features. And then you go around this loop again with your new choice of architecture. And it will often take multiple iterations through this loop until you get to the performance that you want. Let's look at an example of building an email spam classifier. I think many of us passionately hate email spam. And this is a problem that I worked on years ago and also was involved in starting an app anti-spam conference once years ago. The example on the left is what a highly spammy email might look like. Day of the week, buy now Rolex watches and spammers will sometimes deliberately misspell words like these watches, medicine, and mortgages in order to try to trip up a spam recognizer. And in contrast, this email on the right is an actual email I once got from my younger brother Alfred about getting together for Christmas. So how do you build a classifier to recognize spam versus non spam emails? One way to do so would be to train a supervised learning algorithm where the input features x will be the features of an email and the output label y will be one or zero depending on whether a spam or not spam. So one way this application is an example of text classification because you're taking a text document that is an email and try to classify it as either spam or non spam. One way to construct the features of the email would be to say, take the top 10,000 words in the English language or in some other dictionary and use them to define features x1 x2 through x 10,000. So for example, given this email on the right, if the list of words we have is a, Andrew, buy, deal, discount, and so on, then given the email on the right, we would set these features to be say zero or one depending on whether or not that word appears. So the word a does not appear. The word Andrew does appear. The word buy does appear. Deal does, discount does not, and so on. And so you can construct 10,000 features of this email. And there are many ways to construct the feature vector. Another way would be to let these numbers not just be one or zero, but actually count the number of times a given word appears in the email. So if buy appears twice, maybe you want to set this to two, but setting it to just one or zero actually works decently well. Given these features, you can then train a classification algorithm such as a logistic regression model or a neural network to predict y given these features x. After you've trained your initial model, if it doesn't work as well as you wish, you will quite likely have multiple ideas for improving the learning algorithm's performance. For example, it's always tempting to collect more data. In fact, I have friends that have worked on very large scale honeypot projects, and these are projects that create a large number of fake email addresses and tries deliberately to get these fake email addresses into the hands of spammers so that when they send spam email to these fake emails, well, we know these are spam messages. And so this is a way to get a lot of spam data. Or you might decide to work on developing more sophisticated features based on the email routing. Email routing refers to the sequence of compute service, sometimes around the world, that the email has gone through on its way to reach you. And emails actually have what's called email header information. That is information that keeps track of how the email has traveled across different servers, across different networks to find its way to you. And sometimes the path that an email has traveled can help tell you if it was sent by a spammer or not. Or you might work on coming up with more sophisticated features from the email body that is the text of the email. So in the features I talked about last time, discounting and discount might be treated as different words, but maybe they should be treated as the same words. Or you might decide to come up with algorithms to detect misspellings or deliberate misspellings like watches, medicine, and mortgage. And this too could help you decide if an email is spammy. So given all of these and possibly even more ideas, how can you decide which of these ideas are more promising to work on? Because choosing the more promising paths forward can speed up your project easily 10 times compared to if you were to somehow choose some of the less promising directions. For example, we've already seen that if your algorithm has high bias rather than high variance, then spending months and months on a honeypot project may not be the most fruitful direction. But if your algorithm has high variance, then collecting more data could help a lot. So during the interlude of machine learning development, you may have many ideas for how to modify the model or the data. And it will be coming up with different diagnostics that could give you a lot of guidance on what choices for the model or data or other parts of the architecture could be most promising to try. In the last several videos, we've already talked about bias and variance. In the next video, I'd like to start describing to you the error analysis process, which is a second key set of ideas for gaining insights about what architecture choices might be fruitful. So that's the iterative loop of machine learning development. And using the example of building a spam classifier, let's take a look at what error analysis looks like. We'll talk about that in the next video.
[{"start": 0.0, "end": 7.0, "text": " In the next few videos, I'd like to share with you what it's like to go through the"}, {"start": 7.0, "end": 12.8, "text": " process of developing a machine learning system so that when you are doing so yourself, hopefully"}, {"start": 12.8, "end": 18.32, "text": " you'll be in a position to make great decisions at many stages of the machine learning development"}, {"start": 18.32, "end": 19.32, "text": " process."}, {"start": 19.32, "end": 24.92, "text": " Let's take a look first at the iterative loop of machine learning development."}, {"start": 24.92, "end": 28.72, "text": " This is what developing a machine learning model will often feel like."}, {"start": 28.72, "end": 33.72, "text": " First, you decide on what is the overall architecture of your system."}, {"start": 33.72, "end": 39.239999999999995, "text": " And that means choosing your machine learning model as well as deciding what data to use,"}, {"start": 39.239999999999995, "end": 42.36, "text": " maybe picking the hyperparameters and so on."}, {"start": 42.36, "end": 48.4, "text": " Then, given those decisions, you would implement and train a model."}, {"start": 48.4, "end": 52.480000000000004, "text": " And as I've mentioned before, when you train a model for the first time, it will almost"}, {"start": 52.480000000000004, "end": 56.08, "text": " never work as well as you want it to."}, {"start": 56.08, "end": 62.0, "text": " The next step that I recommend then is to implement or to look at a few diagnostics,"}, {"start": 62.0, "end": 66.16, "text": " such as looking at the bias and variance of your algorithm, as well as something we'll"}, {"start": 66.16, "end": 69.96, "text": " see in the next video called error analysis."}, {"start": 69.96, "end": 75.48, "text": " And based on the insights from the diagnostics, you can then make decisions like, do you want"}, {"start": 75.48, "end": 82.32, "text": " to make your neural network bigger or change the lambda regularization parameter or maybe"}, {"start": 82.32, "end": 86.6, "text": " add more data or add more features or subtract features."}, {"start": 86.6, "end": 91.6, "text": " And then you go around this loop again with your new choice of architecture."}, {"start": 91.6, "end": 96.3, "text": " And it will often take multiple iterations through this loop until you get to the performance"}, {"start": 96.3, "end": 98.11999999999999, "text": " that you want."}, {"start": 98.11999999999999, "end": 102.32, "text": " Let's look at an example of building an email spam classifier."}, {"start": 102.32, "end": 106.19999999999999, "text": " I think many of us passionately hate email spam."}, {"start": 106.19999999999999, "end": 112.28, "text": " And this is a problem that I worked on years ago and also was involved in starting an app"}, {"start": 112.28, "end": 115.56, "text": " anti-spam conference once years ago."}, {"start": 115.56, "end": 119.6, "text": " The example on the left is what a highly spammy email might look like."}, {"start": 119.6, "end": 126.36, "text": " Day of the week, buy now Rolex watches and spammers will sometimes deliberately misspell"}, {"start": 126.36, "end": 133.56, "text": " words like these watches, medicine, and mortgages in order to try to trip up a spam recognizer."}, {"start": 133.56, "end": 138.28, "text": " And in contrast, this email on the right is an actual email I once got from my younger"}, {"start": 138.28, "end": 142.0, "text": " brother Alfred about getting together for Christmas."}, {"start": 142.0, "end": 150.52, "text": " So how do you build a classifier to recognize spam versus non spam emails?"}, {"start": 150.52, "end": 157.34, "text": " One way to do so would be to train a supervised learning algorithm where the input features"}, {"start": 157.34, "end": 164.4, "text": " x will be the features of an email and the output label y will be one or zero depending"}, {"start": 164.4, "end": 167.48, "text": " on whether a spam or not spam."}, {"start": 167.48, "end": 174.28, "text": " So one way this application is an example of text classification because you're taking"}, {"start": 174.28, "end": 180.51999999999998, "text": " a text document that is an email and try to classify it as either spam or non spam."}, {"start": 180.51999999999998, "end": 186.04, "text": " One way to construct the features of the email would be to say, take the top 10,000 words"}, {"start": 186.04, "end": 193.83999999999997, "text": " in the English language or in some other dictionary and use them to define features x1 x2 through"}, {"start": 193.83999999999997, "end": 196.33999999999997, "text": " x 10,000."}, {"start": 196.34, "end": 203.96, "text": " So for example, given this email on the right, if the list of words we have is a, Andrew,"}, {"start": 203.96, "end": 214.14000000000001, "text": " buy, deal, discount, and so on, then given the email on the right, we would set these"}, {"start": 214.14000000000001, "end": 219.42000000000002, "text": " features to be say zero or one depending on whether or not that word appears."}, {"start": 219.42000000000002, "end": 221.64000000000001, "text": " So the word a does not appear."}, {"start": 221.64000000000001, "end": 223.8, "text": " The word Andrew does appear."}, {"start": 223.8, "end": 227.04000000000002, "text": " The word buy does appear."}, {"start": 227.04000000000002, "end": 230.22, "text": " Deal does, discount does not, and so on."}, {"start": 230.22, "end": 234.92000000000002, "text": " And so you can construct 10,000 features of this email."}, {"start": 234.92000000000002, "end": 238.22, "text": " And there are many ways to construct the feature vector."}, {"start": 238.22, "end": 243.28, "text": " Another way would be to let these numbers not just be one or zero, but actually count"}, {"start": 243.28, "end": 246.68, "text": " the number of times a given word appears in the email."}, {"start": 246.68, "end": 252.04000000000002, "text": " So if buy appears twice, maybe you want to set this to two, but setting it to just one"}, {"start": 252.04, "end": 256.0, "text": " or zero actually works decently well."}, {"start": 256.0, "end": 262.03999999999996, "text": " Given these features, you can then train a classification algorithm such as a logistic"}, {"start": 262.03999999999996, "end": 269.32, "text": " regression model or a neural network to predict y given these features x."}, {"start": 269.32, "end": 275.12, "text": " After you've trained your initial model, if it doesn't work as well as you wish, you will"}, {"start": 275.12, "end": 280.03999999999996, "text": " quite likely have multiple ideas for improving the learning algorithm's performance."}, {"start": 280.04, "end": 283.64000000000004, "text": " For example, it's always tempting to collect more data."}, {"start": 283.64000000000004, "end": 288.64000000000004, "text": " In fact, I have friends that have worked on very large scale honeypot projects, and these"}, {"start": 288.64000000000004, "end": 294.12, "text": " are projects that create a large number of fake email addresses and tries deliberately"}, {"start": 294.12, "end": 299.56, "text": " to get these fake email addresses into the hands of spammers so that when they send spam"}, {"start": 299.56, "end": 303.40000000000003, "text": " email to these fake emails, well, we know these are spam messages."}, {"start": 303.40000000000003, "end": 307.32000000000005, "text": " And so this is a way to get a lot of spam data."}, {"start": 307.32, "end": 312.4, "text": " Or you might decide to work on developing more sophisticated features based on the email"}, {"start": 312.4, "end": 313.4, "text": " routing."}, {"start": 313.4, "end": 320.76, "text": " Email routing refers to the sequence of compute service, sometimes around the world, that"}, {"start": 320.76, "end": 324.44, "text": " the email has gone through on its way to reach you."}, {"start": 324.44, "end": 328.96, "text": " And emails actually have what's called email header information."}, {"start": 328.96, "end": 333.76, "text": " That is information that keeps track of how the email has traveled across different servers,"}, {"start": 333.76, "end": 337.48, "text": " across different networks to find its way to you."}, {"start": 337.48, "end": 343.32, "text": " And sometimes the path that an email has traveled can help tell you if it was sent by a spammer"}, {"start": 343.32, "end": 345.48, "text": " or not."}, {"start": 345.48, "end": 351.15999999999997, "text": " Or you might work on coming up with more sophisticated features from the email body that is the text"}, {"start": 351.15999999999997, "end": 352.58, "text": " of the email."}, {"start": 352.58, "end": 358.78, "text": " So in the features I talked about last time, discounting and discount might be treated as"}, {"start": 358.78, "end": 364.47999999999996, "text": " different words, but maybe they should be treated as the same words."}, {"start": 364.47999999999996, "end": 369.55999999999995, "text": " Or you might decide to come up with algorithms to detect misspellings or deliberate misspellings"}, {"start": 369.55999999999995, "end": 372.71999999999997, "text": " like watches, medicine, and mortgage."}, {"start": 372.71999999999997, "end": 376.82, "text": " And this too could help you decide if an email is spammy."}, {"start": 376.82, "end": 382.47999999999996, "text": " So given all of these and possibly even more ideas, how can you decide which of these ideas"}, {"start": 382.47999999999996, "end": 384.76, "text": " are more promising to work on?"}, {"start": 384.76, "end": 390.48, "text": " Because choosing the more promising paths forward can speed up your project easily 10"}, {"start": 390.48, "end": 395.8, "text": " times compared to if you were to somehow choose some of the less promising directions."}, {"start": 395.8, "end": 401.44, "text": " For example, we've already seen that if your algorithm has high bias rather than high variance,"}, {"start": 401.44, "end": 406.64, "text": " then spending months and months on a honeypot project may not be the most fruitful direction."}, {"start": 406.64, "end": 410.9, "text": " But if your algorithm has high variance, then collecting more data could help a lot."}, {"start": 410.9, "end": 415.64, "text": " So during the interlude of machine learning development, you may have many ideas for how"}, {"start": 415.64, "end": 418.79999999999995, "text": " to modify the model or the data."}, {"start": 418.79999999999995, "end": 423.85999999999996, "text": " And it will be coming up with different diagnostics that could give you a lot of guidance on what"}, {"start": 423.85999999999996, "end": 429.64, "text": " choices for the model or data or other parts of the architecture could be most promising"}, {"start": 429.64, "end": 431.59999999999997, "text": " to try."}, {"start": 431.59999999999997, "end": 436.28, "text": " In the last several videos, we've already talked about bias and variance."}, {"start": 436.28, "end": 442.67999999999995, "text": " In the next video, I'd like to start describing to you the error analysis process, which is"}, {"start": 442.67999999999995, "end": 450.7, "text": " a second key set of ideas for gaining insights about what architecture choices might be fruitful."}, {"start": 450.7, "end": 454.84, "text": " So that's the iterative loop of machine learning development."}, {"start": 454.84, "end": 460.0, "text": " And using the example of building a spam classifier, let's take a look at what error analysis looks"}, {"start": 460.0, "end": 461.0, "text": " like."}, {"start": 461.0, "end": 468.0, "text": " We'll talk about that in the next video."}]