Fundamentals of Dask Transcripts
Chapter: Dask-ML
Lecture: Hyperparameter tuning

Login or purchase this course to watch this video and the rest of the course contents.
0:00 So we've successfully fit our first model, the k-nearest neighbors model. Now it's time to talk about 'Hyper parameters and "hyper
0:07 parameter Tuning". Which can be very compute intensive and demanding in terms of CPU.
0:13 And so this is a realm in which distributed compute even in a small or medium data sense can be very useful as we'll see. 'Hyperparameters'.
0:21 What are they? They're predefined attributes of models that impact their performance.
0:26 So remember in the K-nearest neighbors example we selected K is equal to three. We define that ahead of time.
0:33 But perhaps a model with K = 5 has more predictive power and is more accurate
0:38 So maybe we want that essentially 'Hyperparameter Tuning' is looking at the space of
0:45 all these different hyper parameters and seeing how the model performs for all of them and then choosing the one that performs best.
0:52 Okay, so in our case we want to check how the model performs with different values of K and then select the most performance value of K.
1:00 There are lots of ways to do this. We're going to use a method called "GridSearchCV".
1:04 Which is grid search cross validation essentially this sets up a big grid across all the
1:10 hyper parameters and perform something called cross validation. Which we're not going to get into now. But if you want go and check out the docs,
1:17 we're not going to execute the code here because it takes a bit of time. So for pedagogical purposes and purposes of efficiency,
1:23 we're just going to talk through it. So we "import GridSearchCV". Then we want to specify the hyper parameters to be explored.
1:31 Okay. And we set them up in a Python dictionary where the keys are the names of the hyper parameters we want to tune and the values are a list of
1:41 the values we want we want to explore. So we're gonna explore 3,5 and 8 as values for N-neighbors And there's another argument
1:47 Another hyper parameter called "weights". And you can check out the documentation as to what this actually is and we're going
1:53 to choose two different ones "uniform" and "distance". All right. We execute this code we instantiate as we have before our classifier
2:00 We then assigned a grid search the function with the following arguments. A GridSearchCV. We pass it the estimator we want to fit,
2:10 which is neigh for 'k-Neighbors classifier'. The grid we pass it (verbose=2) which gives us a detailed output and then
2:18 how many folds in the "Cross Validation" we want to do. And once again, if you want to check out the documentation,
2:23 you can use 2345 is relatively standard. The more folds the more time it takes and then you perform the fit as before
2:30 passing it, the feature variables and then the output or target variable. You can see what happened here getting two folds for each of six candidates.
2:38 Now, why are there six candidates? We've got a three by two grid. So we have six pairs, three uniform three distance,
2:47 five uniform five distance, eight uniform eight distance. Okay, So then we saw that took around four minutes on my system.
2:55 Now we've done that. We want to see what the best parameters were and what score they produced and what we actually see.
3:03 When we look at the 'best_params' attributes. We see 'n_neighbors' was 8 and 'weights': 'distance'. Then we can see what the best score was.
3:12 And we saw that when 'n_neighbors = 8 and weights = distance. The score was very close to 90% accuracy,
3:20 which is pretty good. See you in the next video to explore doing this all in a Distributed Setting. I can't wait.


Talk Python's Mastodon Michael Kennedy's Mastodon