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
Do you want to learn technology from me? Check codebasics.io/ for my affordable video courses.
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.👍🏻
I love that you go through the example the hard way and introduce the cross validation after
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!
Couldn't ask for a better teacher to teach machine learning. Truly exceptional !!!!Thank You so much for all your efforts.
what an amazing explanation. Finally! I understood cross validation concept so clearly. Thank You so much.
@codebasics
4 жыл бұрын
Glad it was helpful!
Great stuff indeed. I'm learning machine learning from scratch and this was very helpful. Keep up the good work, kudos!
Probably the best machine learning tutorials out there... Very good job Thanks!
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.
What an excellent video, thank you! I got lost in other written tutorials, this was finally a clear explanation!
@codebasics
4 жыл бұрын
Hey, thanks for the comment. Keep learning. 👍
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.
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
4 жыл бұрын
Mast pelluri, I am glad you liked it and thanks for recommending it to your friends 🙏👍
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
3 жыл бұрын
Happy to help
🌹 You are way way... way better than all of my Machine learning professor at school!
The best and the smilpest explanation for cross validation i could find after so mush searching.! Keep up the good work!
Finnaly a video explaining de X_train, X_test, y_train,y_teste. Thank you!
Thanks man! You're really helping me out finishing my university project in machine learning.
@codebasics
4 жыл бұрын
Christian I am glad to hear you are making a progress on your University project 😊 I wish you all the best 👍
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 😊.
Thank you. This video solved so many questions at once. Nicely done.
You make exquisite content, I'd love to see more!
only one channel who has pure quality not beating around the bush thanks dhaval sir for your contribution
@codebasics
3 жыл бұрын
Thanks Vishal
I watch several videos of CV but your video is well explained, thank you, thank you very much sir, keep uploading videos sir
Thank for the very useful and free tutorial series. Salute to you sir!
Great tutorials with easy to understand examples. Thanks so much!
This is the most helpful video regarding this topic. Thank you so much!
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!
You are a great instructor and explain concepts in a very understandable and relatable manner. Thank you
@codebasics
3 жыл бұрын
I am happy this was helpful to you.
This is such an amazing, clear explanation. Thank you so much!
@codebasics
3 жыл бұрын
Glad it was helpful!
Your video's on machine learning is way bettet than any online paid video's. so keep growing..
This is an EXCELLLENT explanation. Straighfoward and simplified....Thank you.
@codebasics
3 жыл бұрын
Glad it was helpful!
thank you so much, i am so grateful for a teacher like you.
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
4 жыл бұрын
Pankaj I am happy it has helped you. :) And yes I am in process of uploading many new tutorials on ML. stay tuned!
Don't have any words, you're teaching style and knowledge is amazing ✨...
This is the best video I have watched on Machine learning. Well done!
@codebasics
3 жыл бұрын
Glad you liked it!
Best Explanation I have ever seen. Outstanding job!
@codebasics
4 жыл бұрын
I am happy this was helpful to you
You solved one of my biggest confusion.....Thanks a lot sir
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
5 ай бұрын
pretty ironic and yet amusing at the same time
Thank you sooooo much. You simplified that beautifully.
great work..waiting for more videos on DEEP LEARNING!!
Thanks for creating rather authentic content on this topic compare to others. It is more clear!
@codebasics
3 жыл бұрын
Glad it was helpful!
Thank you so much for the detailed explanation.
Great. You made things look very easy & boosts the confidence. Thank you.
@codebasics
3 жыл бұрын
Happy to help!
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
2 жыл бұрын
after taking cv=5 and C=6 svm is 98.67%
@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
Sir please post more videos regarding ML...... Its really useful for me and others... Thank you so much for your contribution...
Useful for identifying many differnt types of categories.
your tutorial are saving my life
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%
Dhanyavaad Sir. Bhagwaan aapko swasth aur khush rakhien humesha. You are my god.
what a nice way to do your videos thanks a lot, i have learned a lot keep doing it
Greatly explained man. Thank you
Love your explanation, Thank you very much sir
thank you for this series. it is helping me a lot.
Really helpful, thank you so much I was stuck on this for a long time 🙌
@codebasics
3 жыл бұрын
Glad it was helpful!
Amazing explanation ! Thank you :)
Super clear explanation, I have been searching for this one, by seeing this video makes me perfect, tq.
@codebasics
3 жыл бұрын
Glad it was helpful!
Excellent tutorial, thank you!
So simple. You're a good teacher
@codebasics
3 жыл бұрын
Glad you think so!
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?
Great explanation, thank you!
thank you! this saved my life
very simple n lovely teaching......u r simple n great... thank u so much sir
@codebasics
4 жыл бұрын
Thanks rahul for your kind words of appreciation
honestly , this video was great!Tnx
thank you for this video. Excellent presentation of the material with clear explanations
@codebasics
3 жыл бұрын
Michael, I am happy you find it useful
pretty good explanation and you have made my concept clear!!!!!!!
@codebasics
4 жыл бұрын
Alekha I am glad you liked it 😊
Keep up the good work. Cheers man!
wow!! Thank you!! I understand now. And thanks also for providing the code.
@codebasics
3 жыл бұрын
I am happy this was helpful to you.
You are the best man ....Thanks very much.
nice n helpful. video with practice is more helpful than just lecture without practice session
@codebasics
4 жыл бұрын
😊👍
Very nicely explained! Thank you
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
Thank you so much. Very helpful.
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?
Wonderful teaching. Thanks.
wonderful explaination. Great tutorial series
Now i understand this concept. Thank you sir😃
@codebasics
3 жыл бұрын
I am happy this was helpful to you.
Thank you so much. It helped me a lot!!!
@codebasics
3 жыл бұрын
I am happy this was helpful to you.
Excellent explanation of cross-validation and parameter tuning...
@codebasics
4 жыл бұрын
Thanks for feedback Subhronil.
simply great !! 🙏
THIS IS AMAZING THANK YOU!
Thank you very much for your class. Its very useful for the beginners.
@codebasics
4 жыл бұрын
I am happy you liked it Vishnu :)
What Else I can say, AWESOME❤
Thanks Man! Great Tutorial
Good explanation..Gained some confidence to enhance my skills in this area..
@codebasics
3 жыл бұрын
All the best
it is amazing explanation , grate job ...
This is one of the best explanation of Kfold Cross Validation!!! Thank you so much for sharing this valuable video . :))
@codebasics
4 жыл бұрын
😊👍
Great explanation, Salute for this knowledge sharing and great tutorial
@codebasics
4 жыл бұрын
👍🙏
Nice Explanation. Thank you Sir
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
3 жыл бұрын
That is awesome!
Thanks for sharing and really it's helpful
love your teaching pattern sir
Thanks!!! great tutorial!!
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%!
Very nicely explained!
The way you teach is awesome! I request to make tutorials on Neural Network if you are in that field. Thankyou!
@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.
Mind blowing explanation ..
gr8 video , sir. Thank u so much
Great explanation!
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
Sir, really a very good explanation... finally i understood it very well.....
@codebasics
3 жыл бұрын
Glad it helped!
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
Жыл бұрын
mine too...