Machine Learning Tutorial Python 12 - K Fold Cross Validation

Many times we get in a dilemma of which machine learning model should we use for a given problem. KFold cross validation allows us to evaluate performance of a model by creating K folds of given dataset. This is better then traditional train_test_split. In this tutorial we will cover basics of cross validation and kfold. We will also look into cross_val_score function of sklearn library which provides convenient way to run cross validation on a model
#MachineLearning #PythonMachineLearning #MachineLearningTutorial #Python #PythonTutorial #PythonTraining #MachineLearningCource #MachineLearningModel #sklearn #sklearntutorials #scikitlearntutorials
Code: github.com/codebasics/py/blob...
Exercise: Exercise description is avialable in above notebook towards the end
Exercise solution: github.com/codebasics/py/blob...
Topics that are covered in this Video:
0:00 Introduction
0:21 Cross Validation
1:02 Ways to train your model( use all available data for training and test on same dataset)
2:08 Ways to train your model( split available dataset into training and test sets)
3:26 Ways to train your model (k fold cross validation)
4:26 Coding (start) (Use hand written digits dataset for kfold cross validation)
8:23 sklearn.model_selection KFold
9:10 KFold.split method
12:21 StratifiedKFold
19:45 cross_val_score
Do you want to learn technology from me? Check codebasics.io/?... for my affordable video courses.
Next Video:
Machine Learning Tutorial Python - 13: K Means Clustering: • Machine Learning Tutor...
Populor Playlist:
Data Science Full Course: • Data Science Full Cour...
Data Science Project: • Machine Learning & Dat...
Machine learning tutorials: • Machine Learning Tutor...
Pandas: • Python Pandas Tutorial...
matplotlib: • Matplotlib Tutorial 1 ...
Python: • Why Should You Learn P...
Jupyter Notebook: • What is Jupyter Notebo...
Tools and Libraries:
Scikit learn tutorials
Sklearn tutorials
Machine learning with scikit learn tutorials
Machine learning with sklearn tutorials
To download csv and code for all tutorials: go to github.com/codebasics/py, click on a green button to clone or download the entire repository and then go to relevant folder to get access to that specific file.
🌎 My Website For Video Courses: codebasics.io/?...
Need help building software or data analytics and AI solutions? My company www.atliq.com/ can help. Click on the Contact button on that website.
#️⃣ Social Media #️⃣
🔗 Discord: / discord
📸 Dhaval's Personal Instagram: / dhavalsays
📸 Codebasics Instagram: / codebasicshub
🔊 Facebook: / codebasicshub
📱 Twitter: / codebasicshub
📝 Linkedin (Personal): / dhavalsays
📝 Linkedin (Codebasics): / codebasics
🔗 Patreon: www.patreon.com/codebasics?fa...

Пікірлер: 590

  • @codebasics
    @codebasics2 жыл бұрын

    Do you want to learn technology from me? Check codebasics.io/ for my affordable video courses.

  • @MrSparshtiwari
    @MrSparshtiwari3 жыл бұрын

    After watching so many different ML tutorial videos and literally so many i have just one thing to say, the way you teach is literally the best among all of them. You name any famous one like Andrew NG or sentdex but you literally need to have prerequisites to understand their videos while yours are a treat to the viewers explained from so basics and slowly going up and up. And those exercises are like cherry on the top. Never change your teaching style sir yours is the best one.👍🏻

  • @beansgoya
    @beansgoya5 жыл бұрын

    I love that you go through the example the hard way and introduce the cross validation after

  • @tatendaVIDZ90
    @tatendaVIDZ902 жыл бұрын

    that approach of doing the manual method of what cross_val_score is doing in the background and then introducing the method! God send! Brilliant. Brilliant I say!

  • @AltafAnsari-tf9nl
    @AltafAnsari-tf9nl3 жыл бұрын

    Couldn't ask for a better teacher to teach machine learning. Truly exceptional !!!!Thank You so much for all your efforts.

  • @rajnichauhan1286
    @rajnichauhan12864 жыл бұрын

    what an amazing explanation. Finally! I understood cross validation concept so clearly. Thank You so much.

  • @codebasics

    @codebasics

    4 жыл бұрын

    Glad it was helpful!

  • @knbharath5947
    @knbharath59474 жыл бұрын

    Great stuff indeed. I'm learning machine learning from scratch and this was very helpful. Keep up the good work, kudos!

  • @parikshitshahane6799
    @parikshitshahane67993 жыл бұрын

    Probably the best machine learning tutorials out there... Very good job Thanks!

  • @nuraishahzainal1660
    @nuraishahzainal16602 жыл бұрын

    Hi, I'm from Malaysia. I came across your video and I am glad I did it. super easy to understand and I'm currently preparing to learn deep learning. already watch your Python, Pandas, and currently ML videos. thank you for making all these videos. you making our life easier Sir. Sincerely, your student from Malaysia.

  • @synaestheticVI
    @synaestheticVI4 жыл бұрын

    What an excellent video, thank you! I got lost in other written tutorials, this was finally a clear explanation!

  • @codebasics

    @codebasics

    4 жыл бұрын

    Hey, thanks for the comment. Keep learning. 👍

  • @imposternaruto
    @imposternaruto2 жыл бұрын

    My teacher is frustratingly bad. I am learning from your videos so that I can get a good grade in my class. Thank you for taking some time to demonstrate what is happening. When you showed me with the example at 10:47, I finally understood.

  • @mastijjiv
    @mastijjiv4 жыл бұрын

    Your videos are AMAZING man!!! I have already recommended these videos to my colleagues in my University who is taking Machine Learning course. They are also loving it...!!! Keep it up champ!

  • @codebasics

    @codebasics

    4 жыл бұрын

    Mast pelluri, I am glad you liked it and thanks for recommending it to your friends 🙏👍

  • @AlphaGodzilla1
    @AlphaGodzilla13 жыл бұрын

    I have never seen anyone who can explain Machine Learning and Data Science so easily.. I used to be scared in Machine Learning and Data science, then after seeing your videos, I am now confident that I can do it by myself. Thank you so much for all these videos.... 👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏

  • @codebasics

    @codebasics

    3 жыл бұрын

    Happy to help

  • @nicoleluo6692
    @nicoleluo6692 Жыл бұрын

    🌹 You are way way... way better than all of my Machine learning professor at school!

  • @layanibandaranayake9406
    @layanibandaranayake94063 жыл бұрын

    The best and the smilpest explanation for cross validation i could find after so mush searching.! Keep up the good work!

  • @ricardogomes9528
    @ricardogomes95283 жыл бұрын

    Finnaly a video explaining de X_train, X_test, y_train,y_teste. Thank you!

  • @christiansinger2497
    @christiansinger24974 жыл бұрын

    Thanks man! You're really helping me out finishing my university project in machine learning.

  • @codebasics

    @codebasics

    4 жыл бұрын

    Christian I am glad to hear you are making a progress on your University project 😊 I wish you all the best 👍

  • @zunairnoor2745
    @zunairnoor274510 ай бұрын

    Thanks sir! Your tutorials are really helpful for me. Hope I'm gonna see all of them and make my transition from mechanical to AI successful 😊.

  • @alerttrade2356
    @alerttrade23564 жыл бұрын

    Thank you. This video solved so many questions at once. Nicely done.

  • @apeculiargentleman6925
    @apeculiargentleman69255 жыл бұрын

    You make exquisite content, I'd love to see more!

  • @vishalrai2859
    @vishalrai28593 жыл бұрын

    only one channel who has pure quality not beating around the bush thanks dhaval sir for your contribution

  • @codebasics

    @codebasics

    3 жыл бұрын

    Thanks Vishal

  • @KK-rh6cd
    @KK-rh6cd3 жыл бұрын

    I watch several videos of CV but your video is well explained, thank you, thank you very much sir, keep uploading videos sir

  • @kmchentw
    @kmchentw2 жыл бұрын

    Thank for the very useful and free tutorial series. Salute to you sir!

  • @learnerlearner4090
    @learnerlearner40904 жыл бұрын

    Great tutorials with easy to understand examples. Thanks so much!

  • @helloonica8515
    @helloonica85152 жыл бұрын

    This is the most helpful video regarding this topic. Thank you so much!

  • @Suigeneris44
    @Suigeneris444 жыл бұрын

    Your videos are really good! The explanation is crisp and succinct! Love your videos! Keep posting! By the way, you may not realize it, but you are changing peoples' lives by educating them! Jai Hind!

  • @barackonduto5286
    @barackonduto52863 жыл бұрын

    You are a great instructor and explain concepts in a very understandable and relatable manner. Thank you

  • @codebasics

    @codebasics

    3 жыл бұрын

    I am happy this was helpful to you.

  • @nnennaumelloh8834
    @nnennaumelloh88343 жыл бұрын

    This is such an amazing, clear explanation. Thank you so much!

  • @codebasics

    @codebasics

    3 жыл бұрын

    Glad it was helpful!

  • @mohammadpatel2569
    @mohammadpatel25695 жыл бұрын

    Your video's on machine learning is way bettet than any online paid video's. so keep growing..

  • @oscarmuhammad4072
    @oscarmuhammad40723 жыл бұрын

    This is an EXCELLLENT explanation. Straighfoward and simplified....Thank you.

  • @codebasics

    @codebasics

    3 жыл бұрын

    Glad it was helpful!

  • @anirbanc88
    @anirbanc88 Жыл бұрын

    thank you so much, i am so grateful for a teacher like you.

  • @learnwithfunandenjoy3143
    @learnwithfunandenjoy31434 жыл бұрын

    AWESOME AWESOME..... Excellent video you have created. I'm learning ML since past more than 1 years and heard almost more 400 videos. Your videos are AWESOME.... Please make complete series on ML... Thanks.

  • @codebasics

    @codebasics

    4 жыл бұрын

    Pankaj I am happy it has helped you. :) And yes I am in process of uploading many new tutorials on ML. stay tuned!

  • @piyushbarthwal1722
    @piyushbarthwal17229 ай бұрын

    Don't have any words, you're teaching style and knowledge is amazing ✨...

  • @josephnnodim8244
    @josephnnodim82443 жыл бұрын

    This is the best video I have watched on Machine learning. Well done!

  • @codebasics

    @codebasics

    3 жыл бұрын

    Glad you liked it!

  • @abdulazizalqallaf1704
    @abdulazizalqallaf17044 жыл бұрын

    Best Explanation I have ever seen. Outstanding job!

  • @codebasics

    @codebasics

    4 жыл бұрын

    I am happy this was helpful to you

  • @yoyomovieclips8813
    @yoyomovieclips88133 жыл бұрын

    You solved one of my biggest confusion.....Thanks a lot sir

  • @pablu_7
    @pablu_74 жыл бұрын

    Thank you Sir for this awesome explanation. Iris Dataset Assignment Score Logistic Regression [96.07% , 92.15% , 95.83%] SVM [100% , 96.07% , 97.91%] (Kernel='linear') Decision Tree [98.03 %, 92.15% , 100%] Random Forest [98.03% , 92.15% , 97.91%] Conclusion: SVM works the best model for me .

  • @pranjaysingh4161

    @pranjaysingh4161

    5 ай бұрын

    pretty ironic and yet amusing at the same time

  • @tech-n-data
    @tech-n-data Жыл бұрын

    Thank you sooooo much. You simplified that beautifully.

  • @silentboy2292
    @silentboy22925 жыл бұрын

    great work..waiting for more videos on DEEP LEARNING!!

  • @simaykazc1508
    @simaykazc15083 жыл бұрын

    Thanks for creating rather authentic content on this topic compare to others. It is more clear!

  • @codebasics

    @codebasics

    3 жыл бұрын

    Glad it was helpful!

  • @leelavathigarigipati3887
    @leelavathigarigipati38874 жыл бұрын

    Thank you so much for the detailed explanation.

  • @mvcutube
    @mvcutube3 жыл бұрын

    Great. You made things look very easy & boosts the confidence. Thank you.

  • @codebasics

    @codebasics

    3 жыл бұрын

    Happy to help!

  • @pablu_7
    @pablu_74 жыл бұрын

    After Parameter Tuning Using Cross Validation = 10 and taking average Logistic Regression = 95.34% SVM = 97.34% Decision Tree = 95.34 % Random Forest Classifier = 96.67 % Performance = SVM > Random Forest > Logistic ~ Decision

  • @manu-prakash-choudhary

    @manu-prakash-choudhary

    2 жыл бұрын

    after taking cv=5 and C=6 svm is 98.67%

  • @sriram_cyber5696

    @sriram_cyber5696

    Жыл бұрын

    @@manu-prakash-choudhary After 50 splits 😎😎 Score of Logistic Regression is 0.961111111111111 Score of SVM is 0.9888888888888888 Score of RandomForestClassifier is 0.973111111111111

  • @arijitRC473
    @arijitRC4735 жыл бұрын

    Sir please post more videos regarding ML...... Its really useful for me and others... Thank you so much for your contribution...

  • @Gamesational1
    @Gamesational12 жыл бұрын

    Useful for identifying many differnt types of categories.

  • @Hiyori___
    @Hiyori___3 жыл бұрын

    your tutorial are saving my life

  • @maruthiprasad8184
    @maruthiprasad81842 жыл бұрын

    Thank you very much for excellent explanation. I got accuracy SVC=98.04% , RandomForestClassifier(n_estimators=30)=98.04%, LogisticRegression(max_iter=200)=96.08%

  • @jinks3669
    @jinks36692 жыл бұрын

    Dhanyavaad Sir. Bhagwaan aapko swasth aur khush rakhien humesha. You are my god.

  • @santiagovasquez7775
    @santiagovasquez77754 жыл бұрын

    what a nice way to do your videos thanks a lot, i have learned a lot keep doing it

  • @shamsiddinparpiev51
    @shamsiddinparpiev513 жыл бұрын

    Greatly explained man. Thank you

  • @thineshsubramani
    @thineshsubramani4 жыл бұрын

    Love your explanation, Thank you very much sir

  • @sumayachoya2738
    @sumayachoya27383 ай бұрын

    thank you for this series. it is helping me a lot.

  • @pratiknarkhede1287
    @pratiknarkhede12873 жыл бұрын

    Really helpful, thank you so much I was stuck on this for a long time 🙌

  • @codebasics

    @codebasics

    3 жыл бұрын

    Glad it was helpful!

  • @vikamiller1
    @vikamiller14 жыл бұрын

    Amazing explanation ! Thank you :)

  • @kanyadharani6844
    @kanyadharani68443 жыл бұрын

    Super clear explanation, I have been searching for this one, by seeing this video makes me perfect, tq.

  • @codebasics

    @codebasics

    3 жыл бұрын

    Glad it was helpful!

  • @vijayotnm
    @vijayotnm4 жыл бұрын

    Excellent tutorial, thank you!

  • @MNCAMANI15
    @MNCAMANI153 жыл бұрын

    So simple. You're a good teacher

  • @codebasics

    @codebasics

    3 жыл бұрын

    Glad you think so!

  • @someshkb
    @someshkb4 жыл бұрын

    Thank you very much for the nice explanation. I have one question in this context: Isn't it necessary to use in train_test_split method the 'random_state' to get the same score for any model?

  • @amandaahringer7466
    @amandaahringer74662 жыл бұрын

    Great explanation, thank you!

  • @Afussia
    @Afussia3 жыл бұрын

    thank you! this saved my life

  • @rahuljaiswal9379
    @rahuljaiswal93794 жыл бұрын

    very simple n lovely teaching......u r simple n great... thank u so much sir

  • @codebasics

    @codebasics

    4 жыл бұрын

    Thanks rahul for your kind words of appreciation

  • @behdadkhosraviani4131
    @behdadkhosraviani41314 жыл бұрын

    honestly , this video was great!Tnx

  • @michaelcarlson2058
    @michaelcarlson20583 жыл бұрын

    thank you for this video. Excellent presentation of the material with clear explanations

  • @codebasics

    @codebasics

    3 жыл бұрын

    Michael, I am happy you find it useful

  • @alekhakumarambati9315
    @alekhakumarambati93154 жыл бұрын

    pretty good explanation and you have made my concept clear!!!!!!!

  • @codebasics

    @codebasics

    4 жыл бұрын

    Alekha I am glad you liked it 😊

  • @kunalsoni_
    @kunalsoni_5 жыл бұрын

    Keep up the good work. Cheers man!

  • @DavidMcMinoway
    @DavidMcMinoway3 жыл бұрын

    wow!! Thank you!! I understand now. And thanks also for providing the code.

  • @codebasics

    @codebasics

    3 жыл бұрын

    I am happy this was helpful to you.

  • @jeffallenmbaagborebob5869
    @jeffallenmbaagborebob58693 жыл бұрын

    You are the best man ....Thanks very much.

  • @hridayborah9750
    @hridayborah97504 жыл бұрын

    nice n helpful. video with practice is more helpful than just lecture without practice session

  • @codebasics

    @codebasics

    4 жыл бұрын

    😊👍

  • @zeelpareshmehta1942
    @zeelpareshmehta19422 жыл бұрын

    Very nicely explained! Thank you

  • @panagiotisgoulas8539
    @panagiotisgoulas85392 жыл бұрын

    For the parameter tuning this helps. Just play a bit with indexes due to lists staring from 0 and n_estimators from 1 to match up indexes. scores=[ ] avg_scores=[ ] n_est=range(1,5) #example for i in n_est : model=RandomForestClassifier(n_estimators=i) score=cross_val_score(model,digits.data, digits.target, cv=10) scores.append(score) avg_scores.append(np.average(score)) print('avg score:{}, n_estimator:{}'.format(avg_scores[i-1],i)) avg_scores=np.asarray(avg_scores) #convert the list to array print(' Average accuracy score is {} for n_estimators={} calculated from following accuracy scores: {}'.format(np.amax(avg_scores),np.argmax(avg_scores)+1,scores[np.argmax(avg_scores)])) plt.plot(n_est,avg_scores) plt.xlabel('number of estimators') plt.ylabel('average accuracy') 44 was the best for me

  • @chukwuemekafidelis3512
    @chukwuemekafidelis3512 Жыл бұрын

    Thank you so much. Very helpful.

  • @mohankrishna2188
    @mohankrishna21882 жыл бұрын

    Kudos to you, this was the most the crystal clear explanation so fear I have seen. but one small query how to get train accuracy in cross_validation algorithm?

  • @kannanv8831
    @kannanv88314 жыл бұрын

    Wonderful teaching. Thanks.

  • @humayunnasir6261
    @humayunnasir62613 жыл бұрын

    wonderful explaination. Great tutorial series

  • @milanms4593
    @milanms45933 жыл бұрын

    Now i understand this concept. Thank you sir😃

  • @codebasics

    @codebasics

    3 жыл бұрын

    I am happy this was helpful to you.

  • @user-bm9oy4gx2l
    @user-bm9oy4gx2l5 жыл бұрын

    Thank you so much. It helped me a lot!!!

  • @codebasics

    @codebasics

    3 жыл бұрын

    I am happy this was helpful to you.

  • @neel_in_germany
    @neel_in_germany4 жыл бұрын

    Excellent explanation of cross-validation and parameter tuning...

  • @codebasics

    @codebasics

    4 жыл бұрын

    Thanks for feedback Subhronil.

  • @bhaskarg8438
    @bhaskarg84382 жыл бұрын

    simply great !! 🙏

  • @SupahBro535
    @SupahBro5353 жыл бұрын

    THIS IS AMAZING THANK YOU!

  • @vardhanvishnu618
    @vardhanvishnu6184 жыл бұрын

    Thank you very much for your class. Its very useful for the beginners.

  • @codebasics

    @codebasics

    4 жыл бұрын

    I am happy you liked it Vishnu :)

  • @akashraj.srinivasan
    @akashraj.srinivasan5 жыл бұрын

    What Else I can say, AWESOME❤

  • @davidcalahorrano8681
    @davidcalahorrano86814 жыл бұрын

    Thanks Man! Great Tutorial

  • @ashutoshsrivastava914
    @ashutoshsrivastava9143 жыл бұрын

    Good explanation..Gained some confidence to enhance my skills in this area..

  • @codebasics

    @codebasics

    3 жыл бұрын

    All the best

  • @cantanzim6215
    @cantanzim62154 жыл бұрын

    it is amazing explanation , grate job ...

  • @hpourmamih
    @hpourmamih4 жыл бұрын

    This is one of the best explanation of Kfold Cross Validation!!! Thank you so much for sharing this valuable video . :))

  • @codebasics

    @codebasics

    4 жыл бұрын

    😊👍

  • @samcomnotification8713
    @samcomnotification87134 жыл бұрын

    Great explanation, Salute for this knowledge sharing and great tutorial

  • @codebasics

    @codebasics

    4 жыл бұрын

    👍🙏

  • @piousringlearning
    @piousringlearning5 жыл бұрын

    Nice Explanation. Thank you Sir

  • @AlphaGodzilla1
    @AlphaGodzilla13 жыл бұрын

    I am so close enough to finish your videos and then I'm going to hop into your Machine Learning and Data Science Projects... 😊😊😊😊😊😊😊😊😊😊😊

  • @codebasics

    @codebasics

    3 жыл бұрын

    That is awesome!

  • @gezahagnnegash9740
    @gezahagnnegash97402 жыл бұрын

    Thanks for sharing and really it's helpful

  • @navjotsingh-hl1jg
    @navjotsingh-hl1jg6 ай бұрын

    love your teaching pattern sir

  • @felipeacunagonzalez4844
    @felipeacunagonzalez48444 жыл бұрын

    Thanks!!! great tutorial!!

  • @carpingnyland8518
    @carpingnyland85182 жыл бұрын

    Great video, as usual. Quick question: How were able to get such low scores for svm? I ran it a couple of times and was getting in the upper 90's. So, I set up a for loop, ran 1000 different train_test_split iterations through svm and recorded the lowest score. It came back 97.2%!

  • @girikgarg8
    @girikgarg8 Жыл бұрын

    Very nicely explained!

  • @akshyakumarshrestha5551
    @akshyakumarshrestha55515 жыл бұрын

    The way you teach is awesome! I request to make tutorials on Neural Network if you are in that field. Thankyou!

  • @codebasics

    @codebasics

    5 жыл бұрын

    Akshya I started making videos on neural net. Check my channel, posted first two already..once TF2.0 is stable I will add more.

  • @obheech
    @obheech5 жыл бұрын

    Mind blowing explanation ..

  • @shivangbhardwaj51
    @shivangbhardwaj512 жыл бұрын

    gr8 video , sir. Thank u so much

  • @ahmedelsabagh6990
    @ahmedelsabagh69902 жыл бұрын

    Great explanation!

  • @ignaciozamanillo9659
    @ignaciozamanillo96593 жыл бұрын

    Thanks for the video! I have a question, when you do the cross validation inside the for loop you use the same folds for all the methods. Does the cross_val_score do the same? If not, it is posible to use the same folds in order to get a more accurate comparison. Thanks in advance

  • @deepanshudutta8414
    @deepanshudutta84143 жыл бұрын

    Sir, really a very good explanation... finally i understood it very well.....

  • @codebasics

    @codebasics

    3 жыл бұрын

    Glad it helped!

  • @pappering
    @pappering4 жыл бұрын

    Thank you very much. Very nice explanation. My scores, after taking averages, are as follow: LogisticRegression (max_iter=200) = 97.33% SVC (kernel = poly) = 98.00% DecisionTreeClassifier = 96% RandomForestClassifier (n_estimators=300) = 96.67%

  • @autozoomcarrepairing6497

    @autozoomcarrepairing6497

    Жыл бұрын

    mine too...