How To Train Machine Learning Model Using CPU Multi Cores
Key Takeaways
Demonstrates training machine learning models using CPU multi-cores
Full Transcript
hello all my name is krishnak and welcome to my youtube channel so guys today in this particular video we are going to see how we can train machine learning models using cpu multi-cores now this is an important video guys because there is one specific parameter inside machine learning algorithms which we just normally use but we actually don't know the exact meaning of that and because of that many of my subscribers have asked that particular question even though they have asked this question in my telegram group also and for that purpose i'm planning to make this particular video now first of all uh know one thing that guys if you really want to check how many cpu cores you actually have this cpu cores are very much important uh this cores are also important in deep learning when you're working with gpus right because of that parallel programming parallel execution of the programming will be possible now if you want to see that how many cores you have in your desktop or your laptop first of all just go and open my computer so here you'll be able to see my computers just go and see the properties inside this properties you can see that in my machine i am having 16 core processor some of the people will be having eight core processor right some of the people may have four core processor but in my system it has 16 core processor and along with that you will also have 32 threads so parallel processing is possible in this and similarly if we really want to fashion our machine learning model training we can use this course whenever you have a huge data set for training our models right so in this particular video i'll try to show you that by using cpu multi-cores and then we'll try to see that how the performance gets improved with respect to training of our model so for this particular problem statement we are going to take the wine quality data set so one quality data set is this specific data set i think everybody knows about this particular data set so in this data set you have all these particular features and based on that you have a quality score that is between 0 and 10 right so this is basically a classification problem it can also be considered as a regression problem and it is up to you like how you actually want to solve the reason i have taken this particular data set because the data set is quite simple and i wanted to show you the main thing that how we can run this particular program with cpu multi-cores right so that is the main purpose so i have taken a simple data set and one more thing that i wanted to tell you about it is guys if you really want to test this particular example please make sure that you have a good size of the data set now in this particular case let's see how what is the size of the one wine quality data set itself and as you all know also guys we cannot use gpu of to train our machine learning models but yes nvidia has come up with something called as rapids ai that will allow the machine learning models to be trained in gpus right so you should know this multi-core concept it will be very very important for you now first of all i'm going to import the pandas and then i have downloaded the data set from this particular website you know you just have to go and click in the download section where is the data set so here you can see the data folder and you can download this particular data set you know with respect to anyone right so that particular data set you can actually use and i have the data set over here i've downloaded wine quality white dot csv so i'm going to take this particular example from this you can see white dot csv is there you can take reds it's fine now once you take this i'm going to read this particular data set make sure that you use this separator symbol like this because the data that is present inside this is separated by this particular symbol right now in this particular data set you can see that the output feature is your quality and remaining your independent features are the remaining features that we saw right now the next thing that we are going to do let me just zoom out okay uh yeah i'm going to basically check out what is the data quality that in this output feature how many unique categories i have just to check it out i'm just trying to see so these all are the unique categories that are present in the output features if you want to see the shape you can see that they're approximately around 5000 records so i think that with this we will be at least able to verify if we are going to use some maximum number of scores obviously the time will reduce right apart from that you also have 12 features over here so this is basically your df.head right now in this this code is actually helping you to get the dependent feature so i'm just going to write the code over here get the dependent features right it's pretty much simple all i'm doing is that i'm reading all the features and skipping the last one by this okay and here you'll be able to see that this is my y feature that is the output feature over here again if i really want to see y dot head you'll be able to see it over here right so this is my y dot head and uh coming to the execution now now what i'm going to do is that first of all uh in this i'm just going to say some of the steps first of all i'm going to assign i'll just write it down i will be using a machine learning algorithm so in the first step i'll be using a machine learning algorithm like random forest machine learning i'll go like a random forest right and then what i'm going to do i'm going to also use um i think have you used repeated stratified k-fold uh for the cross validation and then with the help of cross valve score you know we will try to train the model okay so with the cross valve score will try to train the model now when we are initializing all these things the time that will be calculated will be calculated based on this cross val score right so we are going to check it out inside this cross valve score how much time it is taking with different different cores now where i will be specifying the core parameter and all you just wait for some time okay now first of all i'm just going to import uh from time import time so that i'll be able to calculate the time then i have from scale under model selection import repeated stratified k-fold then i have ensemble techniques which i am going to import a random forage classifier and i am going to use the cross valve score so that i will be able to do the cross validation now the first thing that i'm going to do over here is that i'm just going to take the start underscore time and instead of writing over here i'll just paste it over here right so what what it actually does let's see not here also let me see so i'll just remove this and after the cv code i'm going to use it now see now first step is that in the line sixth uh what we have done is that we have initialized the random forest classifier and inside this we have used an underscore estimator is equal to 100 now if i press shift tab okay uh first of all let me just execute this in my above cell so that will be easy for me now if i press shift tab over here in random forest in random forest you have a parameter which is called as an underscore jobs now this is the parameter which will actually help you to basically assign that how many cores should this particular training take from your system suppose if you say n underscore jobs is equal to 1 that basically means that it is going to just use one core of the cpu right if you say 2 then it is going to take the 2 cores if you say three then it is going to take three if you say four then it is going to take four if you say five it is going to take five right that depends on how many number of cores you have right in my system i have 16 cores so what i'll do i'll specify 16. suppose if you want to specify use all the codes and you don't have to check that how many codes you have you can also use minus one right but one thing remember guys the reason i have not written the code over here right i'm not going to write the n underscore jobs over here instead i'll be writing that n underscore jobs inside my cross val score because cross val score helps us to do the cross validation with this repeated stratified k fold so i'll not write it over here but suppose if you are not doing cross validation you can specify your n underscore jobs over here and in the next statement you can write model dot fit x comma y so something like this suppose i'll say n underscore jobs is equal to 2 and then i'll say model dot fit with your x and y right x and y so like this you can also write but in our case we are going to do a cross validation and then we are going to see the time so i'm just going to remove this i'm going to remove this because i don't require it over here and here we go now what i'm going to do is that uh i'm going to use a stratified k fold and here the number of splits will be five uh splits and with respect to each split there will be three repetitions and i've selected some random state value and then finally you'll be able to see that i have started my timer right the timer needs to be calculated in this where my model is very getting trained with my independent feature these are my independent features apart from the last feature all the features are my independent feature over here and this is my y feature right my dependent feature then the scoring parameter that i'm going to use is accuracy then the cross validation technique that i'm going to use is basically repeated stratified k-fold and as said i'm going to use an underscore jobs is equal to 1 just to assign it as one cpu core it should be one cpu code right perfect so one cpu code right now let's see after this what i'm doing i'm using end underscore time is equal to time so i'm just going to give you the parameter over here guys for cpu course we use we use an underscore job right and underscore jobs so here you can see and underscore jobs right then i'm ending my time and then i'm printing my end time minus start time right so this is what i've done so i'm just going to execute it over here and let's see how much time it gets trained by just using one core and obviously there are so many records there's so many iterations that we are going to do you can also increase the number of iteration to see the exact work so here you can see with the help of one core i'm actually getting somewhere around 9.63 seconds and that's a huge time guys 9.63 seconds but yes you have five thousand records and you are taking so much of time right uh if i tried to do this with deep learning it's obviously going to be fast but in deep learning you use epochs iteration and many more things now in the second time when i'm going to use the same code okay i'm going to use the same code and just let me remove this i don't want this okay and i'm going to use the start underscore time after this after this step okay and then i'm going to use this and here now my n underscore jobs will be two right all the other code are exactly same guys i did not make any change the thing is that i'm going to now use two cpu cores and i'm going to see whether the time will decrease or not so if i go and see over here i have set n underscore jobs is equal to 2 and if i press shift enter you'll be able to see that how much time it will take and obviously it should take less than 9.63 seconds now here you can see that it is taking six point one nine five seconds now similarly you do with four cores uh in focus what i'm going to do i'm just going to remove this again i'm going to make the same changes my start time should be after this right and here is everything and here my n underscore jobs is four right and after this i will just say print end time minus start time now with four cores i think it should take less time more uh at least less than this so now it is taking obviously 3.80 seconds now it was 6.195 like this if you really want to utilize all the core so what you have to do so i'm just going to make this change again i'm going to use this over here and if i really want to use all the cores i just have to do minus one okay minus one now when i do this you will be able to see that and if i execute it obviously it is going to take less time so let's execute it so after executing you can see that i'm getting 2.614 seconds by using all my cores right so 2.614 seconds 3.806 6.195 and 9.63 now let's try something else so what i've done over here i am going to remove again this because i have already imported it i have written it multiple times so now here i'm going to take some examples of course so i'm saying that okay do the iteration with one two three four five six seven eight nine course and then uh do the cross validation inside and scores trying to find out the time and print all the time with all the code details right that is what i have done for course this much time stamp was this much seconds right or training time you can say training time training training time right so training time was this much so i'm just going to execute that and remember just doing a for loop with respect to this many iterations now here you'll be observing that you know as the number of codes will be increasing you'll be seeing that the training time will be decreasing so for the core one you can see that for the core one for the code two you can see that it is six four for code training three the time was 4.43 for of course 4 training it was 3.83 yes up to some point definitely it is going to decrease and suddenly if it increases like for core 6 the training time was 3.33 right and then it was 3.35 right i'll tell you why it may have increased because i think for solving your problem statement with just four thousand five thousand records i think for course five till four fif till five cores you can actually use now you can see that in eight cores it is still decreasing right in nine core also it is somewhere around 2.98 so i think after this you probably do not require any more additional code so there is a fluctuation in time itself but yes if you try to do it like that you will definitely be able to see it okay so this was an example of using a multi-course multi-cpu course you know and i showed you example all this particular material will be given in the description of this particular video in the form of github link i hope you like this particular video please do subscribe the channel and just share with all your friends whoever you require to help and yes i'll see you in the next video have a great day thank you one and all bye bye
Original Description
github: https://github.com/krishnaik06/CPU-Multi-Cores
In this video we will see how we can train ML models using CPU Multicores
⭐ Kite is a free AI-powered coding assistant that will help you code faster and smarter. The Kite plugin integrates with all the top editors and IDEs to give you smart completions and documentation while you’re typing. I've been using Kite for a few months and I love it! https://www.kite.com/get-kite/?utm_medium=referral&utm_source=youtube&utm_campaign=krishnaik&utm_content=description-only
All Playlist In My channel
Interview Playlist: https://www.youtube.com/playlist?list=PLZoTAELRMXVM0zN0cgJrfT6TK2ypCpQdY
Complete DL Playlist: https://www.youtube.com/watch?v=9jA0KjS7V_c&list=PLZoTAELRMXVPGU70ZGsckrMdr0FteeRUi
Julia Playlist: https://www.youtube.com/watch?v=Bxp1YFA6M4s&list=PLZoTAELRMXVPJwtjTo2Y6LkuuYK0FT4Q-
Complete ML Playlist :https://www.youtube.com/playlist?list=PLZoTAELRMXVPBTrWtJkn3wWQxZkmTXGwe
Complete NLP Playlist:https://www.youtube.com/playlist?list=PLZoTAELRMXVMdJ5sqbCK2LiM0HhQVWNzm
Docker End To End Implementation: https://www.youtube.com/playlist?list=PLZoTAELRMXVNKtpy0U_Mx9N26w8n0hIbs
Live stream Playlist: https://www.youtube.com/playlist?list=PLZoTAELRMXVNxYFq_9MuiUdn2YnlFqmMK
Machine Learning Pipelines: https://www.youtube.com/playlist?list=PLZoTAELRMXVNKtpy0U_Mx9N26w8n0hIbs
Pytorch Playlist: https://www.youtube.com/playlist?list=PLZoTAELRMXVNxYFq_9MuiUdn2YnlFqmMK
Feature Engineering :https://www.youtube.com/playlist?list=PLZoTAELRMXVPwYGE2PXD3x0bfKnR0cJjN
Live Projects :https://www.youtube.com/playlist?list=PLZoTAELRMXVOFnfSwkB_uyr4FT-327noK
Kaggle competition :https://www.youtube.com/playlist?list=PLZoTAELRMXVPiKOxbwaniXjHJ02bdkLWy
Mongodb with Python :https://www.youtube.com/playlist?list=PLZoTAELRMXVN_8zzsevm1bm6G-plsiO1I
MySQL With Python :https://www.youtube.com/playlist?list=PLZoTAELRMXVMd3RF7p-u7ezEysGaG9JmO
Deployment Architectures:https://www.youtube.com/playlist?list=PLZoTAELRMXVOPzVJiSJAn9Ly27F
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Krish Naik · Krish Naik · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Natural Language Processing|Stemming
Krish Naik
Natural Language Processing|BagofWords
Krish Naik
Gaussian distribution or Normal Distribution in statisctics
Krish Naik
Natural Language Processing|TF-IDF for Machine Learning| Text Prerocessing
Krish Naik
Log Normal Distribution in Statistics
Krish Naik
Covariance in Statistics
Krish Naik
Confusion matrix, Precision, Recall| Data Science Interview questions
Krish Naik
Tutorial 44-Balanced vs Imbalanced Dataset and how to handle Imbalanced Dataset
Krish Naik
Implementing a Spam classifier in python| Natural Language Processing
Krish Naik
Tutorial 11-Exploratory Data Analysis(EDA) of Titanic dataset
Krish Naik
Face Recognition using open CV and VGG 16 Transfer Learning
Krish Naik
Pedestrian Detection using OpenCV from Videos
Krish Naik
Face and Eye Detection from Videos using HAAR Cascade Classifier
Krish Naik
Reading, Writing and Displaying images with Opencv| OpenCV Tutorial
Krish Naik
OpenCV Installation | OpenCV tutorial
Krish Naik
Face and Eye Detection from Images using HAAR Cascade Classifier
Krish Naik
Car Detection using HAAR Cascade and Opencv from Videos.
Krish Naik
Using OpenFace for Face recognition in Keras
Krish Naik
OpenPose Tutorial with Tensorflow
Krish Naik
Multiple Linear Regression using python and sklearn
Krish Naik
Dimensional Reduction| Principal Component Analysis
Krish Naik
Movie Recommender System using Python
Krish Naik
TPR,FPR,FNR,TNR, Confusion Matrix
Krish Naik
Precision, Recall and F1-Score
Krish Naik
Artificial Neural Network for Customer's Exit Prediction from Bank
Krish Naik
GridSearchCV- Select the best hyperparameter for any Classification Model
Krish Naik
RandomizedSearchCV- Select the best hyperparameter for any Classification Model
Krish Naik
K Nearest Neighbor classification with Intuition and practical solution
Krish Naik
K Means Clustering Intuition
Krish Naik
Create custom Alexa Skill- Lambda function- Part2
Krish Naik
Hierarchical Clustering intuition
Krish Naik
Implement Transfer Learning with a generic Code Template
Krish Naik
Gender Classifier and Age Estimator using Resnet Convolution Neural Network
Krish Naik
Unlock Your Application With Your Face using OpenCV
Krish Naik
Draw rectangle from webcam and sketch process it on a live feed
Krish Naik
Complete Life Cycle of a Data Science Project
Krish Naik
How we can apply Machine Learning in Finance
Krish Naik
Deep Learning in Medical Science
Krish Naik
How to switch your career to Data Science.
Krish Naik
Linear Regression Mathematical Intuition
Krish Naik
Handle Categorical features using Python
Krish Naik
Machine Learning Algorithm- Which one to choose for your Problem?
Krish Naik
DBSCAN Clustering Easily Explained with Implementation
Krish Naik
Curse of Dimensionality Easily explained| Machine Learning
Krish Naik
Feature Selection Techniques Easily Explained | Machine Learning
Krish Naik
Tutorial 29-R square and Adjusted R square Clearly Explained| Machine Learning
Krish Naik
Cross Validation using sklearn and python | Machine Learning
Krish Naik
Handling Missing Data Easily Explained| Machine Learning
Krish Naik
Deploy Machine Learning Model using Flask
Krish Naik
Deployment of Deep Learning Model using Flask
Krish Naik
How to Visualize Multiple Linear Regression in python
Krish Naik
K Nearest Neighbour Easily Explained with Implementation
Krish Naik
Predicting Heart Disease using Machine Learning
Krish Naik
Predicting Lungs Disease using Deep Learning
Krish Naik
Stock Sentiment Analysis using News Headlines
Krish Naik
Random Forest(Bootstrap Aggregation) Easily Explained
Krish Naik
Voting Classifier(Hard Voting and Soft Voting Classifier)
Krish Naik
Credit Card Fraud Detection using Machine Learning from Kaggle
Krish Naik
Hyperparameter Optimization for Xgboost
Krish Naik
Tutorial 45-Handling imbalanced Dataset using python- Part 1
Krish Naik
More on: ML Pipelines
View skill →Related Reads
📰
📰
📰
📰
Google Onsite Interview Question #14: Design a High-Throughput Thread-Safe LRU Cache with TTL
Medium · Programming
The Problem With “Best Practices” in .NET Development
Medium · Programming
useEffect Is Not a Lifecycle Method
Dev.to · Yasin Demir
The simplest distributed systems pattern I wish I learned earlier
Medium · Programming
🎓
Tutor Explanation
DeepCamp AI