Machine Learning Tutorial Python 12 - K Fold Cross Validation
Вставка
- Опубліковано 30 чер 2024
- 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...
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
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.
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!
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.
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!
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....
👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏
Happy to help
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!
Probably the best machine learning tutorials out there... Very good job
Thanks!
Exercise solution: github.com/codebasics/py/blob/master/ML/12_KFold_Cross_Validation/Exercise/exercise_kfold_validation.ipynb
Complete machine learning tutorial playlist: ua-cam.com/video/gmvvaobm7eQ/v-deo.html
we needed to use mean() with cross validation to get average mean of accuracy score. i'm guessing you forget to add. anyways video is pretty good and depth.keep producing such videos.
The best and the smilpest explanation for cross validation i could find after so mush searching.! Keep up the good work!
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.
You make exquisite content, I'd love to see more!
What an excellent video, thank you! I got lost in other written tutorials, this was finally a clear explanation!
Hey, thanks for the comment. Keep learning. 👍
🌹 You are way way... way better than all of my Machine learning professor at school!
Thanks man! You're really helping me out finishing my university project in machine learning.
Christian I am glad to hear you are making a progress on your University project 😊 I wish you all the best 👍
only one channel who has pure quality not beating around the bush thanks dhaval sir for your contribution
Thanks Vishal
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 .
pretty ironic and yet amusing at the same time
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!
Finnaly a video explaining de X_train, X_test, y_train,y_teste. Thank you!
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 for the very useful and free tutorial series. Salute to you sir!
I watch several videos of CV but your video is well explained, thank you, thank you very much sir, keep uploading videos sir
Thank you. This video solved so many questions at once. Nicely done.
Your video's on machine learning is way bettet than any online paid video's. so keep growing..
Great tutorials with easy to understand examples. Thanks so much!
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
after taking cv=5 and C=6 svm is 98.67%
@@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
You are a great instructor and explain concepts in a very understandable and relatable manner. Thank you
I am happy this was helpful to you.
This is the best video I have watched on Machine learning. Well done!
Glad you liked it!
This is the most helpful video regarding this topic. Thank you so much!
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.
Pankaj I am happy it has helped you. :) And yes I am in process of uploading many new tutorials on ML. stay tuned!
great work..waiting for more videos on DEEP LEARNING!!
Keep up the good work. Cheers man!
This is an EXCELLLENT explanation. Straighfoward and simplified....Thank you.
Glad it was helpful!
Don't have any words, you're teaching style and knowledge is amazing ✨...
Best Explanation I have ever seen. Outstanding job!
I am happy this was helpful to you
Sir please post more videos regarding ML...... Its really useful for me and others... Thank you so much for your contribution...
Thanks for creating rather authentic content on this topic compare to others. It is more clear!
Glad it was helpful!
This is such an amazing, clear explanation. Thank you so much!
Glad it was helpful!
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
Greatly explained man. Thank you
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%
mine too...
Thank you so much for the detailed explanation.
You solved one of my biggest confusion.....Thanks a lot sir
thank you so much, i am so grateful for a teacher like you.
your tutorial are saving my life
Great. You made things look very easy & boosts the confidence. Thank you.
Happy to help!
Amazing explanation ! Thank you :)
This is one of the best explanation of Kfold Cross Validation!!!
Thank you so much for sharing this valuable video . :))
😊👍
@20:39 of the video, noticed something interesting, by default "cross_val_score()" method generates 3 kfolds... but the default has now changed from 3 to 5 :))
thanks man, i was worried when mine was showing 5 folds results. i thought something was wrong w my code.
@@gandharvsaxena8841 Me too lol, whi I am getting 5
Thankyou man!!
The way you teach is awesome! I request to make tutorials on Neural Network if you are in that field. Thankyou!
Akshya I started making videos on neural net. Check my channel, posted first two already..once TF2.0 is stable I will add more.
What Else I can say, AWESOME❤
Thank you sooooo much. You simplified that beautifully.
14:15 - Here instead of kf.split() we should use folds.split(). Am I correct??
Yes. My notebook has a correction. Check that on GitHub link I have provided in video description
Yes and also just to add to it StratifiedKFold requires X and y both labels to its split method. Stratification is done based on the y labels.
Excellent tutorial, thank you!
Useful for identifying many differnt types of categories.
Nice Explanation. Thank you Sir
wonderful explaination. Great tutorial series
Best tutorial.Liked and subscribed!!!
Dhanyavaad Sir. Bhagwaan aapko swasth aur khush rakhien humesha.
You are my god.
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?
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?
what a nice way to do your videos thanks a lot, i have learned a lot
keep doing it
Hi there!
Excellent video! This greatly explains the concepts and is very helpful! Keep up the awesome work! I have 2x questions please - Please clarify:
1) Since the cross_val_score method is used to get the score for the performance of a machine learning model, when using Stratified K Fold Cross Validation, is it the only performance measure? Can we also use the following, and if yes, how? Please explain with an example please:
- Accuracy
- Precision
- Recall
- Specificity
- F1_Score
- ROC_Curve
- Model Execution Time (How is this possible using Jupyter Notebooks?)
2) Expanding on the content of this UA-cam video, please explain with an example, on how to retrieve the Feature Importance of a machine learning model please? At which stage would this be done? At the end, right? I mean, after we get the average score of a machine learning model using Stratified K Fold Cross Validation?
Thanks a lot in advance. Much appreciated.
Great question.
Great explanation, thank you!
Love your explanation, Thank you very much sir
Thanks!!! great tutorial!!
He did folds = StratifiedKFold(), and said that he will use it because it is better than KFold
but at 14:20, he used kf.split, where kf is KFold.
I think he frogot to use StatifiedKFold.
yeah, i noticed that
Really helpful, thank you so much I was stuck on this for a long time 🙌
Glad it was helpful!
it is amazing explanation , grate job ...
very simple n lovely teaching......u r simple n great... thank u so much sir
Thanks rahul for your kind words of appreciation
Thanks Man! Great Tutorial
Mind blowing explanation ..
Wonderful teaching. Thanks.
honestly , this video was great!Tnx
thank you for this series. it is helping me a lot.
Very nicely explained!
Super clear explanation, I have been searching for this one, by seeing this video makes me perfect, tq.
Glad it was helpful!
Very nicely explained! Thank you
Thank you so much. It helped me a lot!!!
I am happy this was helpful to you.
thank you! this saved 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%
simply great !! 🙏
Great explanation!
You are the best man ....Thanks very much.
I am so close enough to finish your videos and then I'm going to hop into your Machine Learning and Data Science Projects... 😊😊😊😊😊😊😊😊😊😊😊
That is awesome!
THIS IS AMAZING THANK YOU!
Thank you so much. Very helpful.
Great explanation, Salute for this knowledge sharing and great tutorial
👍🙏
love your teaching pattern sir
So simple. You're a good teacher
Glad you think so!
pretty good explanation and you have made my concept clear!!!!!!!
Alekha I am glad you liked it 😊
Now i understand this concept. Thank you sir😃
I am happy this was helpful to you.
best explanation... i like the way u give examples using small data to explain how it actually works. 10:20
no one explains like this... keep doing great work
Glad you liked it
@@codebasics
I have applied K fold on the linear regression's dataset
I used different activation functions & then I get mean & se values
How to pick the best model from the k folds?
Thanks for sharing and really it's helpful
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%!
Thank you very much for your class. Its very useful for the beginners.
I am happy you liked it Vishnu :)
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