How to find the best model parameters in scikit-learn

  Рет қаралды 153,857

Data School

Data School

9 жыл бұрын

In this video, you'll learn how to efficiently search for the optimal tuning parameters (or "hyperparameters") for your machine learning model in order to maximize its performance. I'll start by demonstrating an exhaustive "grid search" process using scikit-learn's GridSearchCV class, and then I'll compare it with RandomizedSearchCV, which can often achieve similar results in far less time.
Download the notebook: github.com/justmarkham/scikit...
Grid search user guide: scikit-learn.org/stable/module...
GridSearchCV documentation: scikit-learn.org/stable/module...
RandomizedSearchCV documentation: scikit-learn.org/stable/module...
Comparing randomized search and grid search: scikit-learn.org/stable/auto_e...
Randomized search video: • Scikit Learn Workshop ...
Randomized search notebook: github.com/amueller/pydata-ny...
Random Search for Hyper-Parameter Optimization: www.jmlr.org/papers/volume13/b...
WANT TO GET BETTER AT MACHINE LEARNING? HERE ARE YOUR NEXT STEPS:
1) WATCH my scikit-learn video series:
• Machine learning in Py...
2) SUBSCRIBE for more videos:
kzbin.info?su...
3) JOIN "Data School Insiders" to access bonus content:
/ dataschool
4) ENROLL in my Machine Learning course:
www.dataschool.io/learn/
5) LET'S CONNECT!
- Newsletter: www.dataschool.io/subscribe/
- Twitter: / justmarkham
- Facebook: / datascienceschool
- LinkedIn: / justmarkham

Пікірлер: 346
@dataschool
@dataschool 3 жыл бұрын
Having problems with the code? I just finished updating the notebooks to use *scikit-learn 0.23* and *Python 3.9* 🎉! You can download the updated notebooks here: github.com/justmarkham/scikit-learn-videos
@compton8301
@compton8301 3 жыл бұрын
Ans thanks for updating it.
@MrGuruPuru
@MrGuruPuru 7 жыл бұрын
just brilliant. Not an inch of fluff in what you teach and you do it so beautifully.
@dataschool
@dataschool 7 жыл бұрын
Wow, thank you so much for your very kind words!
@preethamreddy6726
@preethamreddy6726 4 жыл бұрын
@@dataschool Thank you for such a nice explanation. Can I know this please why I can't get the first element of the tuple? Thank you print (grid.cv_results_[0]) KeyError Traceback (most recent call last) in ----> 1 print (grid.cv_results_[0]) KeyError: 0
@mamacita5636
@mamacita5636 Жыл бұрын
Pls don’t stop making these videos you’re saving my dissertation 😭😭 thank you so much
@dataschool
@dataschool Жыл бұрын
You're very welcome!
@roshanrajsingh4838
@roshanrajsingh4838 3 жыл бұрын
This is straight tutorial I've ever seen. I've not skipped a second of this video.
@dataschool
@dataschool 3 жыл бұрын
Glad it's helpful to you! 🙌
@AbhisarMohapatra
@AbhisarMohapatra 7 жыл бұрын
There's a humbleness in the way you teach and deliver the explanations. It helps me understand very very well whatever the topic is.
@dataschool
@dataschool 7 жыл бұрын
Wow, thank you! I really appreciate your comment.
@MattyTkernow
@MattyTkernow 5 жыл бұрын
That is exactly what I was thinking. If you can't explain it simply, you don't understand it well enough (Einstein). And you sir know what you are taking about!
@anefuoche1053
@anefuoche1053 4 жыл бұрын
At some point my eyes became teary while watching this series. I have never come across such an amazing and passionate teacher. you explain every single thing, even the questions that pop up in my mind it feels like you foresee and address them, what's baffling is that you even tag them as questions before answering them. The additional resources are also pure gold. My God will bless you sir, may you live long and always be happy
@jatingogia4633
@jatingogia4633 3 жыл бұрын
I like the way you explain everything so slowly and briefly. Thank you for such a quality content on ML!
@dataschool
@dataschool 3 жыл бұрын
Thanks for your kind words!
@NB19273
@NB19273 5 жыл бұрын
Succinct, self contained, and very clear. The best video on youtube ive found so far explaining parameter search. Thanks so much!
@dataschool
@dataschool 5 жыл бұрын
Excellent, that's great to hear!
@musasall5740
@musasall5740 6 жыл бұрын
You bring it in every video and make it easy to understand!
@dataschool
@dataschool 6 жыл бұрын
Thanks for your kind comment!
@pankajmathur1504
@pankajmathur1504 8 жыл бұрын
Just want to say, all the video in Scikit series are excellent. Especially you have made so easy to understand the complex topic of cross validation and optimal parameter tuning. Keep up the good work. Can't wait for the next one...
@dataschool
@dataschool 8 жыл бұрын
+Pankaj Mathur Awesome! Thanks so much for your kind words.
@RS-el7iu
@RS-el7iu 4 жыл бұрын
its great i came across your clips... one of the BEST explantions out there. thanks a lot
@dataschool
@dataschool 4 жыл бұрын
You're welcome!
@shahriarrahman6482
@shahriarrahman6482 6 жыл бұрын
I watched the whole playlist in 1 day !! This is one of if not the best sklearn tutorials out..
@dataschool
@dataschool 6 жыл бұрын
Awesome, thank you!
@evanmiller29
@evanmiller29 9 жыл бұрын
Data School thank you so much for these videos. You're showing all the topics that no one has put the time to explain to us plebs. Keep the good work up!
@dataschool
@dataschool 9 жыл бұрын
Evan Miller You're very welcome!
@kevinalkindy
@kevinalkindy 2 жыл бұрын
Thank you for making this video. What a crystal clear explanation!
@dataschool
@dataschool 2 жыл бұрын
You're very welcome! 🙏
@betulchamplin3642
@betulchamplin3642 3 жыл бұрын
your classes are simply AMAZING, thank you so much for all your efforts putting them together!
@dataschool
@dataschool 3 жыл бұрын
Wow, thank you!
@perevales
@perevales 8 жыл бұрын
Your videos are excellent. You have had the ability of explaining ML using Python in a very accessible way. I usually use R but now thanks to your great tutorials I will start using Python. Thanks and please don't stop producing these fantastic tutorials.
@dataschool
@dataschool 8 жыл бұрын
+Pedro Carmona Ibáñez Thanks for your kind comments! I just published a new tutorial (55 minutes): kzbin.info/www/bejne/bmbHpZyDr56nidE As well, I'm teaching a new course on Machine Learning with Text: www.dataschool.io/learn/
@alexisparenty9445
@alexisparenty9445 5 жыл бұрын
Whaoo! Brillant. Very well explained, you speak very clearly too. You certainly have a gift for teaching. Continue the good job
@dataschool
@dataschool 5 жыл бұрын
Thanks very much for your kind words! :)
@dhazra1
@dhazra1 7 жыл бұрын
Kevin, you are an awesome teacher. Not only your knowledge; your teaching style is also so good that it can make extremely happy both the new comers into machine learning as well as those are already in this field but need to understand the concepts further. I have gone through quite a few of your videos in youtube and everywhere it's just outstanding !!!!
@dataschool
@dataschool 7 жыл бұрын
Wow, thank you very much for your kind comments! I'm so glad the videos have been helpful to you!
@nehathakar5622
@nehathakar5622 4 жыл бұрын
Your explanation makes each and every topic so simple and easy to understand. Really, I would like to thank you for your immense efforts for all your videos which are so informative and added resources help us to dig deeper in the related topics.
@dataschool
@dataschool 4 жыл бұрын
Thanks very much for your kind words! 😊
@syedmohdsohail3506
@syedmohdsohail3506 7 жыл бұрын
Kevin and Data School, you have been angels to me. I learned a hell lot in Machine Learning, thank you so much.
@dataschool
@dataschool 7 жыл бұрын
You're very welcome! I'm glad the videos have been helpful to you!
@minchin8041
@minchin8041 7 жыл бұрын
Best gridsearch tutorial on youtube. Thanks!
@dataschool
@dataschool 7 жыл бұрын
You're welcome! Glad it was helpful to you!
@imshafay
@imshafay 6 жыл бұрын
Your the beast mate. I wanted to go through Machine Learning basics Revision, and I'm quite amazed this is the best Video I have ever watched on KZbin, in fact best from all the reading platforms as well.
@dataschool
@dataschool 6 жыл бұрын
Awesome! Thank you so much for your kind words! If you want to support Data School, my Patreon campaign might interest you: www.patreon.com/dataschool/overview
@abhisheksalvi2438
@abhisheksalvi2438 5 жыл бұрын
This is really helpful. Grateful for your efforts taken in creating this resource.
@dataschool
@dataschool 5 жыл бұрын
You're welcome!
@sidk5919
@sidk5919 8 жыл бұрын
U are an amazing teacher...thank you so much.
@dataschool
@dataschool 7 жыл бұрын
You're welcome! Thanks for your kind words :)
@sinanwannous
@sinanwannous 3 жыл бұрын
Thank you so much, one of the best and clearest explanation I've ever came across!!
@dataschool
@dataschool 3 жыл бұрын
Great to hear!
@dataschool
@dataschool 6 жыл бұрын
*Note:* This video was recorded using Python 2.7 and scikit-learn 0.16. Recently, I updated the code to use Python 3.6 and scikit-learn 0.19.1. You can download the updated code here: github.com/justmarkham/scikit-learn-videos
@bandhammanikanta1664
@bandhammanikanta1664 4 жыл бұрын
This helped. Thank you :) :)
@BobDuCharme
@BobDuCharme 9 жыл бұрын
These videos are all really great, and I particularly like how the iPython notebooks serve so well to help me review what was in any particular video. I'd like to put in a vote for one of the future videos to cover clustering.
@dataschool
@dataschool 9 жыл бұрын
Bob DuCharme Great to hear... I spend a lot of time crafting these notebooks! And, thanks for the feedback, I will certainly consider clustering.
@slowcoding
@slowcoding 6 жыл бұрын
Your lectures are very clear and esay to understand. Excellent!!!
@dataschool
@dataschool 6 жыл бұрын
Thanks for your kind comment!
@DEEPAKKUMAR-sw6sb
@DEEPAKKUMAR-sw6sb 5 жыл бұрын
mesmerized by your explanations. Thank you so much!
@dataschool
@dataschool 5 жыл бұрын
You're very welcome!
@ramlimbu886
@ramlimbu886 7 жыл бұрын
Pure gold! Thank you, Kevin!
@dataschool
@dataschool 7 жыл бұрын
You're very welcome! Glad this video was helpful to you!
@ohserra
@ohserra 8 жыл бұрын
A M A Z I N G ! In one day I've learned what I need to get into machine learning in python and scikit-learn. I've been using matlab for a while, and it's overwhelming the possibilities of scikit and the IPython notebook. Thank you again! great job ;) I hope to keep hearing from you!
@dataschool
@dataschool 8 жыл бұрын
+Diogo Gonçalves Wow! What a kind and thoughtful comment! I greatly appreciate it.
@vl4n7684zt
@vl4n7684zt 8 жыл бұрын
If you are running Python 3.4 and getting a "Parameter values should be a list" error, then make the following adjustment to the code to properly read in the range: k_range = list(range(1,31)) Also, as always, print statements in 3.4 require parentheses.
@dataschool
@dataschool 8 жыл бұрын
+Stacy H Thanks for passing along that tip!
@Dualphase90
@Dualphase90 8 жыл бұрын
Thanks Stacy! :)
@chetankv7218
@chetankv7218 6 жыл бұрын
We can use numpy.arange(1,31) instead of range.
@dataschool
@dataschool 6 жыл бұрын
Thanks! I recently updated the code to use Python 3.6 and scikit-learn 0.19.1. The updated code can be found here: github.com/justmarkham/scikit-learn-videos
@fernandonogueira2291
@fernandonogueira2291 3 жыл бұрын
You´re the master! Thanks for such a well explained video.
@dataschool
@dataschool 3 жыл бұрын
Thank you!
@brendensong8000
@brendensong8000 3 жыл бұрын
Another amazing video! Thank you!
@dataschool
@dataschool 3 жыл бұрын
Thanks again!
@philscosta
@philscosta 4 жыл бұрын
Very good video, very good explanation. Thank you!
@compton8301
@compton8301 3 жыл бұрын
You're amazing. Thanks for the free knowledge.
@dataschool
@dataschool 3 жыл бұрын
You're welcome!
@greettheceo395
@greettheceo395 7 жыл бұрын
Ahhh so awesome tutorial , struggling with this part for very long , now it got clear Thanks Regards
@dataschool
@dataschool 7 жыл бұрын
Great to hear!
@asneogy
@asneogy 8 жыл бұрын
hello Kevin - really great videos, love your clear and precise way of explaining concepts yet keeping them accessible. a request - there are not too many seaborn tutorial videos out there. could you consider making some? thanks and keep rocking.
@mdinesk
@mdinesk 8 жыл бұрын
I would love to see more such videos, especially on handling huge datasets with categorical values
@dataschool
@dataschool 8 жыл бұрын
+Dinesh Kumar Murali Thanks for the suggestion! I'll take it into consideration.
@AntonyMapfumo
@AntonyMapfumo 9 жыл бұрын
Thanks. Great explanation. Your videos are very helpful and easy to understand.
@dataschool
@dataschool 9 жыл бұрын
Antony Mapfumo You're very welcome!
@GuRuGeorge03
@GuRuGeorge03 3 жыл бұрын
Thank you so much for this. This is literally gold
@dataschool
@dataschool 2 жыл бұрын
You're welcome!
@nastarankianersi104
@nastarankianersi104 3 жыл бұрын
Thank you so much for this clear and helpful tutorial and all the effort you put in to your work 🌸^^
@dataschool
@dataschool 3 жыл бұрын
You're very welcome!
@pookiechips5496
@pookiechips5496 6 жыл бұрын
Thank you abundantly for everything that you are doing for the world.
@dataschool
@dataschool 6 жыл бұрын
You are very welcome! :)
@swagatmishra9350
@swagatmishra9350 4 жыл бұрын
Thank you very much for such a very beautiful explanation!!!
@dataschool
@dataschool 4 жыл бұрын
Thanks for appreciating!
@AxlRulz666
@AxlRulz666 7 жыл бұрын
I like your talking speed. It gives me enough time to absorb the concepts. May be its just me. Anyways, Thank you very much !
@dataschool
@dataschool 7 жыл бұрын
Great to hear - you're very welcome! :)
@lokeshpaladugula5793
@lokeshpaladugula5793 4 жыл бұрын
really awesome.... great work man... and thank youuuuu
@dataschool
@dataschool 4 жыл бұрын
Thanks!
@russelllavery2281
@russelllavery2281 4 жыл бұрын
Fantastic. We should all join his support group. 5 a month is cheap
@balkiprasanna1984
@balkiprasanna1984 7 жыл бұрын
Thank you so much for this video. You're just amazing.
@dataschool
@dataschool 7 жыл бұрын
Wow, thanks so much! I really appreciate it :)
@mallikarjunsuram4913
@mallikarjunsuram4913 6 жыл бұрын
Brilliant work dude
@dataschool
@dataschool 6 жыл бұрын
Thanks!
@aoife1902
@aoife1902 7 жыл бұрын
Absolutely brilliant, thank you so much!
@dataschool
@dataschool 7 жыл бұрын
You're very welcome!
@behnoushpejhanmanesh4353
@behnoushpejhanmanesh4353 Жыл бұрын
Your teaching and explanations are amazing Kevin! Many thanks for all the effort you have put on preparing these tutorials. Do you have any tutorials about "DecisionTreeClassifier", to which you briefly refer in this video?
@dataschool
@dataschool Жыл бұрын
Thanks for your kind words! I don't have a video tutorial about decision trees, but I do have this lesson notebook: github.com/justmarkham/DAT8/blob/master/notebooks/17_decision_trees.ipynb Hope that helps!
@citizenR1203
@citizenR1203 7 жыл бұрын
Great ! Thanks for your ipython notebook.
@dataschool
@dataschool 7 жыл бұрын
You're welcome!
@JackSimpsonJBS
@JackSimpsonJBS 9 жыл бұрын
Thank-you so much for these amazing tutorials, I've learned so much from them and now I use scikit-learn frequently. Was this the final video or did you have any idea how many you were planning to make in this series?
@dataschool
@dataschool 9 жыл бұрын
***** Excellent, glad to hear! I do have more videos planned, though I haven't yet decided how many more I will make. The next one will come out in a few weeks... stay tuned!
@pengyan1906
@pengyan1906 3 жыл бұрын
You are doing great!
@dataschool
@dataschool 3 жыл бұрын
Thank you!
@saudnaeem
@saudnaeem 5 жыл бұрын
Learned a lot from this video. thank u
@dataschool
@dataschool 5 жыл бұрын
You're welcome!
@sandeeps_
@sandeeps_ 9 жыл бұрын
I found the video series very useful! Thank you! :) Do you plan to have more videos in the future?
@dataschool
@dataschool 9 жыл бұрын
***** You're welcome! I will be creating more videos in the series, though it will be a few weeks from now before I have time to make the next one.
@kwenevdavidapine4661
@kwenevdavidapine4661 3 жыл бұрын
this video is very useful, thank you
@dataschool
@dataschool 3 жыл бұрын
Glad it was helpful!
@RexhepShijaku
@RexhepShijaku 3 жыл бұрын
15:08 just to add something, there is another advise like this : it is better to select an odd value for k, since it may avoid the ties caused during classification . In this case [in the example on video] we have best scores when k=13, k=18, k=20, so probably it picked 13 because it is an odd number. I may be wrong but I heard it somewhere :)
@gracezhao3168
@gracezhao3168 6 жыл бұрын
You are super helpful. Have to give you a thumb up!
@dataschool
@dataschool 6 жыл бұрын
Thanks!
@xiangxinzhang1770
@xiangxinzhang1770 11 ай бұрын
In a typical workflow, you would split your original dataset into a training set and a separate test set. Then, during cross-validation, you further divide the training set into multiple subsets (folds) and iteratively train and evaluate the model on these folds. The test set remains untouched and is used for final evaluation after the model selection or parameter tuning process.
@dataschool
@dataschool 6 ай бұрын
Whether or not you need to do that depends on your goals: Whether you are solely trying to select the best model, or whether you also need an accurate estimate of how that best model will perform on out-of-sample data. The workflow you are proposing is a good one if you care about both goals and you have enough data such that the initial split does not compromise the first goal.
@LonglongGuitar
@LonglongGuitar 7 жыл бұрын
at 19:26, the knn.fit(X, y) is to display the classifier parameters only, since we already instantiate the knn model with the best parameters (1 step before the fitting). in another word, the 'fit' method will always give you the same output, no matter you fit(X_train, y_train), or fit(X_test, y_test), or fit(X, y). It just shows the best parameters in the model. just same as print(knn)
@dataschool
@dataschool 7 жыл бұрын
knn.fit(X, y) is a necessary step in order to train the model with the data. Instantiating the model in the previous step does not train the model, rather it just prepares the model to be trained using certain parameters.
@pradyparyal
@pradyparyal 7 жыл бұрын
I like your way of explanation. Thank you so much for your effort. Could you please upload the videos on unsupervised learning.
@dataschool
@dataschool 7 жыл бұрын
Thanks for your kind words! I'll consider your suggestion for the future.
@thisaintarf
@thisaintarf 4 жыл бұрын
thankyu very much sir, this video helps me a lot
@dataschool
@dataschool 4 жыл бұрын
Great!
@NR_Tutorials
@NR_Tutorials 4 жыл бұрын
thanks for ur videos and nice voice over it ,, we love u sir thanks
@dataschool
@dataschool 4 жыл бұрын
You're welcome!
@sribastavrajguru304
@sribastavrajguru304 5 жыл бұрын
Great, thank you for your great work, its really helpfullllll
@dataschool
@dataschool 5 жыл бұрын
Great to hear!
@JCRMatos
@JCRMatos 9 жыл бұрын
Hello, Can we save the gridsearch "knowledge" to predict at a later time? Isn't it strange that the RandomizedSearch repeated the combo 17, distance? It's assumed that it selects random combos, but it shouldn't select duplicates, should it? Thanks, JM
@dataschool
@dataschool 9 жыл бұрын
João Matos Great questions! Here is scikit-learn's documentation on model persistence, which should allow you to save the best model (grid.best_estimator_): scikit-learn.org/stable/modules/model_persistence.html Regarding duplicates, here is what the documentation says: "If all parameters are presented as a list, sampling without replacement is performed. If at least one parameter is given as a distribution, sampling with replacement is used." Since none of my parameters in that example were distributions, I would think that we shouldn't see any duplicates. However, either the documentation is incorrect on that point, or I'm misunderstanding what the documentation is trying to say.
@augustinemalamsha9251
@augustinemalamsha9251 4 жыл бұрын
u r a great teacher, optimazation, gridsearch, exhaustive search were a mist to me, nut now bcz of u, they kind of on my finger tips
@dataschool
@dataschool 4 жыл бұрын
Great!
@user-cc8kb
@user-cc8kb 6 жыл бұрын
Nice. Thank you very much! :)
@dataschool
@dataschool 6 жыл бұрын
You're welcome! :)
@prakashyadav008
@prakashyadav008 7 жыл бұрын
amazing teaching..thanks
@dataschool
@dataschool 7 жыл бұрын
You're welcome!
@fablapp
@fablapp 7 жыл бұрын
Hi Kevin, thank you so much for sharing this with us. enjoying any single minute of your videos. One question: receiving a warning message when running the .predict method on the dataset: "Passing 1d arrays as data is deprecated in i0.17 and will raise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample." Not sure I am fully understanding what is about. Thanks again!
@dataschool
@dataschool 7 жыл бұрын
Glad you are enjoying the videos! Regarding the warning message, it's complicated to explain, but I discuss it in detail in this blog comment: www.dataschool.io/linear-regression-in-python/#comment-2521926219 Hope that helps!
@deboratoshiekohara2723
@deboratoshiekohara2723 4 жыл бұрын
Thaanks! Congrats Its a great explanation! I was also checking some other videos of yours and a doubt appeared, I wanted to combine the pipe with the gridsearch. For instance I tried to put down the gridsearch within my pipeline and extract the results as pipe.cv_results_, however could not use the .cv_results with pipe. Could you give any hint about the combination pipe for preprocessing and then search grid? Maybe another topic for your videos Thanks!
@MrMmahesh007
@MrMmahesh007 6 жыл бұрын
simply superb, you have amazing teaching skills. Great explanations and material suggested. I wanted to switch my career to MLearning and have been watching all your playlists. Once I complete all your videos, what is the best way to master?any suggestions.
@dataschool
@dataschool 6 жыл бұрын
Thanks so much for your kind words! My thoughts are here: www.dataschool.io/launch-your-data-science-career-with-python/
@hmscfch.7216
@hmscfch.7216 6 жыл бұрын
Hi, Kevin. I noticed that the codes are running slower on my PC (which is a standard one). Can I know what requirements are you recommended on the hardware? Or, any solutions to improve the processing speed? Thank you. And thank you for your 'quick-understanding' tutorials.
@dataschool
@dataschool 6 жыл бұрын
I'm not sure what hardware recommendations to make, I'm sorry!
@suryagaur7440
@suryagaur7440 5 жыл бұрын
Brilliant as usual. Can you please make video on nested and non-nested Cross validation
@dataschool
@dataschool 5 жыл бұрын
Thanks for your suggestion!
@asadulhaqmshani4737
@asadulhaqmshani4737 5 жыл бұрын
Thanks a lot bro
@dataschool
@dataschool 5 жыл бұрын
You're welcome!
@smaxwell89
@smaxwell89 8 жыл бұрын
Hi Kevin, thank you for making these videos as they have served as a very informative introduction to machine learning for me. I've watched each video of the series and studied the code thoroughly. Any recommendations as to what to do next as far as teaching myself machine learning? I'm planning to go back through the videos and study all of the supplemental resources you've provided and then complete the "An Introduction to Statistical Learning with Applications in R" course. Is this a good plan of action or should I focus more so on Python and scikit-learn? My main goal is to use my Physics background along with what I've been teaching myself to become a Data Scientist, but I would greatly appreciate your opinion on the matter. Thank you.
@dataschool
@dataschool 8 жыл бұрын
+smaxwell89 That sounds like a great plan! Here's some advice that I give my data science students: github.com/justmarkham/DAT7/blob/master/other/advice.md
@hocinetedjani7376
@hocinetedjani7376 7 жыл бұрын
Hello, Thank you for your courses :D they are so clear. I have a question : Do you think that I can use GridSearchCV with AdaBoostClassifier ? Because I have a dataset with low frequency of y=1.
@dataschool
@dataschool 7 жыл бұрын
Sure, GridSearchCV can be used with any model for parameter tuning. Good luck!
@DJH3891
@DJH3891 3 жыл бұрын
very good explanation! I still got an issue in understanding your statement at 19:35 - I thought training the model not enirely on all the data available was key, because otherwise you would have no test-set to evaluate or overfit the model??
@jrabyssdragon
@jrabyssdragon 7 жыл бұрын
Hi Kevin! I've a quick question. In this video you explained the SearchCV methods for tuning parameters. Also, I've found that there are some functions to perform feature selection with scikit learn. But I was wondering if there's a way to perform both feature selection and hyperparameter tuning within the same pipeline in scikit-learn. Any insight is appreciated.
@dataschool
@dataschool 7 жыл бұрын
Sure, you can do a GridSearchCV of a Pipeline that contains both a feature selector and a model. This example from the documentation shows something similar: scikit-learn.org/stable/auto_examples/model_selection/grid_search_text_feature_extraction.html Hope that helps!
@SunilKalmady
@SunilKalmady 8 жыл бұрын
Brilliant! You have excellent teaching skills. Please help me understand this better. Like with feature selection, whether finding optimal model (hyper)parameters should also be performed ideally within each cross-validation iteration? If i am not mistaken, you recommend using whole dataset (unsplit) for grid search in this video. Doesn't it constitute as (some form of) training from entire data? I would be happy if you can answer. Anyways, great stuff!!
@dataschool
@dataschool 8 жыл бұрын
+Sunil Kalmady Thanks for your kind words! You are correct that when searching for the optimal model, feature selection and feature engineering should *ideally* occur within each cross-validation fold. However, the question is always whether the added complexity is worth the increase in reliability of your performance estimates. This is a nice, short Q&A on that topic: stats.stackexchange.com/questions/92502/cross-validation-feature-information-outside-the-fold
@SunilKalmady
@SunilKalmady 8 жыл бұрын
+Data School Thank you for your answer!!
@StefanoWalker
@StefanoWalker 6 жыл бұрын
Bravo. Bravo!!!
@dataschool
@dataschool 6 жыл бұрын
You are too kind :)
@nsm9dvarunbabu618
@nsm9dvarunbabu618 2 жыл бұрын
sure definetly
@eldert1735
@eldert1735 5 жыл бұрын
Thanks for the video. I have a question. When you put the parameters in the GridSearchCV, you put the knn as the estimator. 'knn' was instantiated with 'n_neighbors = k', looking at the above code. Does GridSearchCV ignore the things inside the parenthesis of the estimator? Or do we have to put 'n_neighbors = k' inside the KNeighborsClassifier, instead of a specific number to make the code work?
@dataschool
@dataschool 5 жыл бұрын
The parameter grid passed to GridSearchCV will override the parameters passed to knn during instantiation. Hope that helps!
@tirthprakashbal3612
@tirthprakashbal3612 7 жыл бұрын
Hi Kevin, Thanks a lot for this awesome tutorial series. Can you suggest some datasets from Kaggle competitions on which I can practice this knowledge ?
@dataschool
@dataschool 7 жыл бұрын
I don't have any particular suggestions, but there are lots of past competitions in which the datasets are still available. I'd recommend choosing a competition in which the topic interests you!
@boringpsychology9737
@boringpsychology9737 2 жыл бұрын
great thanks
@dataschool
@dataschool 2 жыл бұрын
You're welcome!
@sreemantokesh3999
@sreemantokesh3999 5 жыл бұрын
Your tutorials are so so great. Thank you for everything Kevin. I see the GridsearchCV and RandomizedSearch is kind of similar to Gradient Descent and Stochastic Descent. Am I wrong??? Can yo do a video where you explain Stochastic Gradient and it's Variation??
@dataschool
@dataschool 5 жыл бұрын
Thanks for your suggestion! I'll consider it for the future.
@happyandhealthy888
@happyandhealthy888 Жыл бұрын
excellent parameters
@dataschool
@dataschool Жыл бұрын
Thanks!
@mikemyers9524
@mikemyers9524 6 жыл бұрын
many many thanks. Just one question. If I do gridsearch, say, with an SVR with the parameter C [0.001, 0.01, 0.1, 1, 10, 100] and finally find an optimal parameter C: Can I reduce the parameter space to this optimal parameter C when I would like to do permutations for statistical testing ? Or do I loose some information during the permutation procedure ? THX!
@dataschool
@dataschool 6 жыл бұрын
It's a great question, but I'm not sure of the answer... sorry!
@MatthewAds
@MatthewAds 9 жыл бұрын
Super helpful videos! What do you do when you want to do categorisation on a dataset which consists of many categorical variables? As I understand scikitlearn models expect numeric values always? What is the best way to convert datasets full of categorical data represented by strings into integer representations for use in scikitlearn models? Is that even an approach you would advise?
@dataschool
@dataschool 9 жыл бұрын
Matt Adshead Great question! Yes, scikit-learn expects numeric values. For unordered categorical features, you generally represent them as dummy variables. For ordered categorical variables, you can represent them using "sensible" numeric values. More details are available in part 3 of this notebook: nbviewer.ipython.org/github/justmarkham/DAT7/blob/master/notebooks/12_advanced_model_evaluation.ipynb
@chetakabra8
@chetakabra8 8 жыл бұрын
one of the best explanation using pathon notebook ..can you please upload video for feature selection
@dataschool
@dataschool 8 жыл бұрын
+akash kabra I'll consider making one for the future, thanks!
@dataschool
@dataschool 5 жыл бұрын
You might be interested in my recent video about feature selection: kzbin.info/www/bejne/j5Kufph3oa2ap7M
@JCRMatos
@JCRMatos 9 жыл бұрын
Hello, Does grid.best_score_ take into account both the mean and the std or just the mean? Thanks for the series. Keep it up. JM
@dataschool
@dataschool 9 жыл бұрын
João Matos The documentation says it picks the "highest score", so I assume that means it only takes the mean into account (and not the standard deviation). However, if you find differently, please let me know!
@AndreasMueller
@AndreasMueller 8 жыл бұрын
Very nice video series :) I'd be curious if you used any of my material apart from the video you linked to [everything I do is CC-0 unless published via a publisher so don't fear the lawyers]. I found the continuous talking / walking through for videos really hard, you do a much better job than me, I think.
@dataschool
@dataschool 8 жыл бұрын
+Andreas Mueller Thanks very much for the compliments - I'm flattered! No, I'm pretty sure I didn't use any outside materials, with the exception of some images. I basically created every notebook from scratch. Regarding the talking during videos: It takes some getting used to, for sure! I scripted this series (every word and every action), which made the recording easier, but took FOREVER (probably 150 hours of work for a 4-hour series!!) I changed tactics for my latest video series (pandas), which is mostly unscripted, and thus I can make videos a lot faster. Looking forward to your book! Tentative release date? :)
@AndreasMueller
@AndreasMueller 8 жыл бұрын
+Data School Summer It was announced for June but I don't think we'll make that. Stay tuned for an early release. I scripted my O'Reilly series (tried without script first, totally failed) and it also to for ever. I'll check out your pandas videos. Keep up the good work! I'm glad this material is openly available -- mine is not :-/
@dataschool
@dataschool 8 жыл бұрын
+Andreas Mueller Cool, I'll be on the lookout for the book this summer!
@silasmurithi4706
@silasmurithi4706 5 жыл бұрын
Awesome tutorial, I would like to know what happens if you tune parameters of different classification models to give similar predictions? Is it a good idea or a bad one? And how to go about it?
@dataschool
@dataschool 5 жыл бұрын
Glad you liked the tutorial! Not sure what you mean by "tuning to give similar predictions"... Instead, if you try tuning another model, your goal is to optimize for your chosen evaluation metric, not to make sure it gives similar predictions to any other model. Does that make sense?
@pinkanrout818
@pinkanrout818 6 жыл бұрын
simply Awesome!!!Thanks a lot for all your videos. I have a question here...Grid search we use to get the best hyper parameter as in this case n_neighbors. But how it will be helpful in linerar/logistic regression . In linear we are not using any tuning parameter (linreg.fit(x,Y)). In deep learning the role of learning rate comes may be that time it will be useful..not sure in scikit how it helps in linear regression.
@dataschool
@dataschool 6 жыл бұрын
You're right that linear regression has no tuning parameters. However, logistic regression does have a tuning parameter, so grid search is helpful there.
@stephenstanton6860
@stephenstanton6860 7 жыл бұрын
At about 20:00, in In[23] and In[24] you said that grid.predict() and knn.predict() do the same thing. Well when I do "print grid" it says n_neighbors=30. It seems kinda redundant that the GridSearchCV returns the best model but also exposes a field called best_estimator_. Any insight on these things?
@dataschool
@dataschool 7 жыл бұрын
In my opinion, GridSearchCV is just trying to provide the user with different options to fit different use cases. Sometimes the user might want to just see the best parameters, sometimes they want a copy of the best fitted model, and sometimes they want to immediately use the best fitted model to make predictions.
@jesuscortes9110
@jesuscortes9110 7 жыл бұрын
This is really a wonderful material and really helpful to be used for teaching. Is there any resource I might use for analytically calculating predicted probabilities ? thanks!
@dataschool
@dataschool 7 жыл бұрын
Thanks for your kind comments! I'm not sure what you mean by "analytically calculating predicted probabilities". Could you explain in more detail, or give an example? Thanks!
@jesuscortes9110
@jesuscortes9110 7 жыл бұрын
I mean , for a given classifier, and for a given feature vector, to calculate the predicted probability for each class
@dataschool
@dataschool 7 жыл бұрын
Thanks for clarifying! Yes, most scikit-learn classifiers include a 'predict_proba' method that outputs the predicted probabilities of class membership. I cover that in video 9 in this series: kzbin.info/www/bejne/bmbHpZyDr56nidE
@henrikmellgren9920
@henrikmellgren9920 6 жыл бұрын
I have a question regarding the feedback from GridsearchCV class. I am doing a project where i am using Keras to build a Artificiell neural network and tuning the hyperparameters with the help of Gridsearch. I keep getting very large difference in scoring when i compare the split_test_score and split_train_score and even after much research i am still confused as to how they work. I have read a lot of guides, but i cant find any clarity in how split_test_score is calculated ?
@dataschool
@dataschool 6 жыл бұрын
I'm not 100% sure without doing some research, I'm sorry!
@nathankong8732
@nathankong8732 2 жыл бұрын
Hi, quick question, why don’t you split the data before grid search? Also how would you do a confusion matrix using this model?
@marathiManus10
@marathiManus10 3 жыл бұрын
Love simplicity in your approach! Excuse me for my naive question - So How to determine if cluster size 13 is optimal or 17 is optimal? If one was to use said KNN logic in a TRULY real life situation, should he choose 13 or 17?
@dariuszspiewak5624
@dariuszspiewak5624 3 жыл бұрын
Not sure if I can take on Kevin's role here but I remember from his teachings that you should choose the parameter that makes your model SIMPLER. Since 17 gives you simpler decision boundaries, you should choose 17. In general, in KNN you should use the highest parameter out of the best performing ones.
@giorgos253
@giorgos253 3 жыл бұрын
If I have to do a classification in text with 7-8 classes categorical , which is the best algorithm to use SVC or someone else? Can you give a hint ?
How to evaluate a classifier in scikit-learn
54:47
Data School
Рет қаралды 151 М.
Selecting the best model in scikit-learn using cross-validation
35:54
버블티로 체감되는 요즘 물가
00:16
진영민yeongmin
Рет қаралды 55 МЛН
Sprinting with More and More Money
00:29
MrBeast
Рет қаралды 190 МЛН
Just try to use a cool gadget 😍
00:33
123 GO! SHORTS
Рет қаралды 85 МЛН
Homemade Professional Spy Trick To Unlock A Phone 🔍
00:55
Crafty Champions
Рет қаралды 56 МЛН
Hyperparameter Tuning in Python with GridSearchCV
14:41
NeuralNine
Рет қаралды 13 М.
Comparing machine learning models in scikit-learn
26:42
Data School
Рет қаралды 186 М.
Hyperparameter Optimization - The Math of Intelligence #7
9:51
Siraj Raval
Рет қаралды 109 М.
How do I encode categorical features using scikit-learn?
27:59
Data School
Рет қаралды 137 М.
8.3. Hyperparameter Tuning - GridSearchCV and RandomizedSearchCV
13:36
Data science in Python: pandas, seaborn, scikit-learn
34:30
Data School
Рет қаралды 185 М.
How I’d learn ML in 2024 (if I could start over)
7:05
Boris Meinardus
Рет қаралды 933 М.
버블티로 체감되는 요즘 물가
00:16
진영민yeongmin
Рет қаралды 55 МЛН