Training and Tuning Models Workout
- 02:29
Practice training and tuning machine learning models using a for loop.
Downloads
No associated resources to download.
Transcript
In your Jupyter Notebook, complete the following steps. First, write a for loop to train all of the models in the model's dictionary. Then after training each model print the key followed by is trained and tuned. As a tip, executing this code cell trains all of the hyper parameter configurations for each of your 5 model classes, and so it may take some time to complete be patient and don't worry if it takes a second before you see the output. Also, again, don't be alarmed by the data convergence warning. It's okay.
Now, don't be alarmed by this data convergence warning. As long as your code matches what you see here, your models will be trained and they will work correctly. The for loop says for each key in the models keys iterable, which we know is equal to these values right here, call that item with models key. So that's the same as writing models dot lasso. And that's gonna get us the value, which we know is that grid search function. So take that grid search function and use the scikit-learn fit function to train it using our input training data and our target training data. And what that does is it takes the model, so it takes lasso or ridge or elastic net, and it gives it these inputs and has it compare those inputs to the target and identify relationships. This is where your machine learning model really goes to work. It's going to identify those relationships, and it's also going to tune all of the hyperparameters by the time this process is finished. Your machine learning model now has a good understanding of the relationships in your data and how to use future inputs to make accurate predictions. As this for loop cycles through all five of our models when it finishes, we want it to print the name of the model and then tell us that it's trained and tuned. When you execute this cell, you might get some big crazy data convergence warning. Don't worry about that, just scroll all the way to the bottom using the scroll bar on the right. And at the very bottom you should see GB is trained and tuned because that's the final item in our model keys iterable. After you execute this code cell be patient. The machine learning algorithms are doing a lot of work, so it might take a little bit of time for the models to look at all the input data and train on it and tune the hyperparameters. So wait, it might take up to a few minutes, but after a few minutes, you should see GB is trained and tuned at the bottom of that output.