Тёмный

Machine Learning Tutorial Python - 19: Principal Component Analysis (PCA) with Python Code 

codebasics
Подписаться 1 млн
Просмотров 180 тыс.
50% 1

PCA or principal component analysis is a dimensionality reduction technique that can help us reduce dimensions of dataset that we use in machine learning for training. It helps with famous dimensionality curse problem. In this video we will understand what PCA is all about, write python code for handwritten digits dataset classification and then use PCA to train the same model using PCA.
Code: github.com/codebasics/py/blob...
Exercise: github.com/codebasics/py/blob...
⭐️ Timestamps ⭐️
00:00 Theory
09:12 Coding
23:04 Exercise
Do you want to learn technology from me? Check codebasics.io/?... for my affordable video courses.
🌎 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.
🎥 Codebasics Hindi channel: / @codebasicshindi
#️⃣ Social Media #️⃣
🔗 Discord: / discord
📸 Dhaval's Personal Instagram: / dhavalsays
📸 Instagram: / codebasicshub
🔊 Facebook: / codebasicshub
📱 Twitter: / codebasicshub
📝 Linkedin (Personal): / dhavalsays
📝 Linkedin (Codebasics): / codebasics
❗❗ DISCLAIMER: All opinions expressed in this video are of my own and not that of my employers'.

Опубликовано:

 

27 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 156   
@codebasics
@codebasics 2 года назад
Do you want to learn technology from me? Check codebasics.io/ for my affordable video courses.
@rakeshbullet7363
@rakeshbullet7363 Год назад
Awesome videos - Simple explanations. A balanced approach to teaching with a right mixture of theory and practicals and not overwhelming the learners . i loved the approach - After seeing numerous ML training videos from across the spectrum , this is far most the best one i have seen . Thank you for taking time to create these videos .
@mohitupadhayay1439
@mohitupadhayay1439 2 года назад
The last few minutes were BANG ON! This is what i wanted to hear. Thanks!
@mayishamaliha6369
@mayishamaliha6369 9 месяцев назад
super helpful for newbies not scaring them off with too many statistical terms and getting overwhelmed. thank u so much
@dushyyanta5305
@dushyyanta5305 Год назад
You are the best! I am doing PG in DS but still, I watch your videos for better understanding. Kudos! Keep it up!
@Rainbow-lj5pp
@Rainbow-lj5pp 2 месяца назад
This is a really easy to understand and thorough explanation of principal component analysis. Many others I watched were either too technical and math theory oriented or to basic in showing how to use the function but not what it does. This is a great balance of understanding and practicality.
@TK-fx8dh
@TK-fx8dh 2 года назад
My long await topic!!!! Thank you for posting this PCA lesson
@bhaskarg8438
@bhaskarg8438 2 года назад
Thank you, PCA concept is clearly explained . Need to understand in actual real life scenarios, what we consider, the performance or process time
@K.Charz0
@K.Charz0 2 года назад
Thanks sir the great work, your explanation makes ML easier for sure 🙏
@prakashkoneti7630
@prakashkoneti7630 Год назад
I would really appreciate for your hard work in making these videos and decoding the complex to easy..
@akinloluwababalola6666
@akinloluwababalola6666 2 года назад
Hello Code basics. I usually enjoy your videos as I learn a lot from them. Can you make a video on association rules, apriori algorithms and any machine model that deals with the determination of interrelationships amongst variables? Thank you
@luciamatamorospava4382
@luciamatamorospava4382 8 месяцев назад
it's like the 10th video i'm watching on PCA and the FIRST one I understand, thank you so much!
@AkaExcel
@AkaExcel 2 года назад
@codebasics Thank You for Teaching and helping us!
@jinks3669
@jinks3669 2 года назад
Another very informative video. DHANYAVAAD ! :)
@dees900
@dees900 Год назад
great explanation on PCA. It's an abstract concept to grasp. well done
@Maniclout
@Maniclout 2 года назад
Amazing explanation, I understand PCA now.
@guillermokinderman8267
@guillermokinderman8267 Год назад
I was trying to understand PCA, this video helped me a lot
@boogersincoffee
@boogersincoffee 2 года назад
Ahhhhhh I've been struggling to understand this and this cleared everything up, thank you
@mukeshkumaryadav350
@mukeshkumaryadav350 Год назад
It was an amazing explanation of PCA without much mathematics and eigen value and vector which scares me. Interesting learning 1. we can know variance explained by each PC which helps.
@user-yv3ib9so5d
@user-yv3ib9so5d Месяц назад
Masters in Data Science in the UK and still loves watching only your videos :-)
@BG4INDIA
@BG4INDIA Год назад
Impressed with the clarity of explaination
@codebasics
@codebasics Год назад
glad you liked it
@mansijswarnkar4389
@mansijswarnkar4389 Год назад
Wonderful, as always - thanks for making this video, it has helped me a lot ! Regards
@leamon9024
@leamon9024 Год назад
Thanks for this amazing tutorial. Hope you could do one video about when to use feature selection and feature extraction, or even combination of them.
@MohammadYs77
@MohammadYs77 2 года назад
Very informative and practical.
@manjularathore1076
@manjularathore1076 2 года назад
You are absolutely amazing.
@souhamahmoudi7745
@souhamahmoudi7745 Год назад
Thanks for sharing, it's highly appreciated
@purebackend1993
@purebackend1993 2 года назад
You kill it, amazing!
@jjanna07751
@jjanna07751 2 года назад
thanku ..pca explained very easily
@anirudh7150
@anirudh7150 4 месяца назад
Thank you Sir. It was really helpful.
@maruthiprasad8184
@maruthiprasad8184 2 года назад
Thank you very much for simple and great explanation. I got higher accuracy in SVM=86.74 %, after PCA I got accuracy in RF=73.06
@pranjiljain4500
@pranjiljain4500 Год назад
But timing and machine power also decreases heavily
@mohammeddanishreza4902
@mohammeddanishreza4902 Год назад
can you share the github link for your code please.
@mr.luvnagpal7407
@mr.luvnagpal7407 2 года назад
Thankyouu so much for this amazing video
@DrizzyJ77
@DrizzyJ77 Месяц назад
Thank you code basics❤
@punnarahul4068
@punnarahul4068 2 года назад
great looking for more videos dhaval bhai............../
@ernestanonde3218
@ernestanonde3218 2 года назад
This is the best channel on RU-vid. You are simply amazing. You just saved my career. Thanks a million
@ernestanonde3218
@ernestanonde3218 11 месяцев назад
@Karthiktanu I am.a student of data science and analytics
@ernestanonde3218
@ernestanonde3218 11 месяцев назад
@@Thanusree234 yes
@salahmahmoud2119
@salahmahmoud2119 Год назад
You are the best!!! 👏
@asamadawais
@asamadawais Год назад
I am watching this vedio 2nd or 3rd time. @Dhavel you best among equals...👍👍
@albertoachavalrodriguez2461
@albertoachavalrodriguez2461 2 года назад
Great video!
@richardshaw8326
@richardshaw8326 4 месяца назад
Great explanation on PCA. @codebasics: I must have missed it though, but after running the PCA to identify which features will give the results, I missed where one might get the features.
@aaditya1267
@aaditya1267 Год назад
nice explanation !!
@tamirat9797
@tamirat9797 4 месяца назад
Thank you 🙏
@usamaalicraft3646
@usamaalicraft3646 2 года назад
Thanks sir 😊😊
@tigrayrimey6418
@tigrayrimey6418 2 года назад
Nice points.
@babalolamayowamercy186
@babalolamayowamercy186 2 года назад
Nice video Thank you
@nyangwindicollins1018
@nyangwindicollins1018 2 года назад
Superb
@lostcat7494
@lostcat7494 Год назад
thank you so much
@sarangali4595
@sarangali4595 Год назад
Sir also make a video on how PCA actually works and what type of information we can gain from the loadings like how are these features affecting the label
@suriyaprakashgopi
@suriyaprakashgopi 9 месяцев назад
nicely done
@swagsterfut9992
@swagsterfut9992 2 года назад
at 17:35, shouldn't we be doing pca.fit_transform()on our scaled dataset (X_scaled in our case) rather than on X?
@geoafrikana
@geoafrikana Год назад
This came to my mind also. Perhaps the accuracy would have been higher if he scaled before pca.
@anirudhgangadhar6158
@anirudhgangadhar6158 Год назад
Yes it should be on X_scaled.
@debatradas1597
@debatradas1597 2 года назад
Thank you so much
@LamNguyen-jp5vh
@LamNguyen-jp5vh 2 года назад
Hi, I just want to ask why we use StandardScaler instead of MinMaxScaler in the lecture (not exercise). Thank you so much for your help!
@Ooo12376
@Ooo12376 2 года назад
Please also explain the math behind it. You get questions on math behind PCA in interviews. People ask the derivation of PCA
@mohammadhosseinkazemi8558
@mohammadhosseinkazemi8558 Год назад
Thank you for the video. I have one problem, though: Shouldn't we first split the data into training and test sets, then scale each set separately using StandardScaler(), RobustScaler(), etc. ?
@siddheshmhatre2811
@siddheshmhatre2811 Год назад
Thanks ❤
@nriezedichisom1676
@nriezedichisom1676 4 месяца назад
Thank you
@gnaneshgn8341
@gnaneshgn8341 2 года назад
Nice Video sir. Please make a video for the math behind PCA. Thanks in Advance Sir
@geekyprogrammer4831
@geekyprogrammer4831 2 года назад
ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-FgakZw6K1QQ.html this should be sufficient if you want to know mathematics
@shubhanshugupta9754
@shubhanshugupta9754 2 года назад
U can get best of pcs by taking log(total features)
@ogobuchiokey2978
@ogobuchiokey2978 Год назад
Your videos have helped me to complete my MSc research. Thank you for being a great teacher. I do have a question, during the explanation, you said we should always use PCA on the scaled data but during implementation, you used the unscaled data. Could you explain this?
@kreativeaman7688
@kreativeaman7688 6 месяцев назад
I had the same question following through.
@kreativeaman7688
@kreativeaman7688 6 месяцев назад
I tried using PCA on the scaled data and used it in SVM, Logistic Regression and RandomForest classifier, but the results were almost the same as to using regular data with PCA.
@sohailshaikh786
@sohailshaikh786 Год назад
Thanks
@talkingbirb2808
@talkingbirb2808 4 месяца назад
I would add that reducing number of columns should help with overfitting
@anirudhgangadhar6158
@anirudhgangadhar6158 Год назад
Highest accuracy: SVM - 85.83%, after PCA (3 PCs), accuracy was 83.87%. For all 3 models, accuracy slightly (
@slainiae
@slainiae 3 месяца назад
Highest accuracy 0.8729 with SVM (linear) and with PCA n_components = 11.
@nastaran1010
@nastaran1010 5 месяцев назад
Hi. I have a question. why when you perform PCA, for input, you did not give (x_scaled), you gave x?????
@tobe7602
@tobe7602 2 года назад
Hi Good tutorial, i think you must use X_train in pca.fit_transform and not X. Thanks
@uthmantanko2881
@uthmantanko2881 2 года назад
Hi. I might not be making any sense here but I wanted to know if same thing could be achieved with entropy and information gain. We know information gain tells you the feature with the most information or importance as a number . Therefore, in theory, we can remove all the features with really low information gains. I think it would this would work with discrete data better. I don't know if it already exists. If it does, what method does this. If it doesn't, can I know if this solution is practical.
@sarangali4595
@sarangali4595 Год назад
Sir please also make a video on how to find relations using descriptive technique.
@sevicore
@sevicore 2 года назад
I HAVE SOME QUESTIONS: 1)if you use ur PCA data that has been scaled before doing any train test split...wouldnt it cause Data Lakeage? 2) should not the target be dropped?
@hrithiksarma1204
@hrithiksarma1204 2 года назад
I had the same doubt, have you got any update on this ?
@krishnadaskv2197
@krishnadaskv2197 2 года назад
I am getting around 80 % score when using PCA(0.99999) in exercise, which is higher than the score before using PCA, and also getting a better score without removing outliers.
@codebasics
@codebasics 2 года назад
That’s the way to go kv, good job working on that exercise
@youktinathbhowmick4673
@youktinathbhowmick4673 2 года назад
Thanks for the explanation. I have one question: When you are doing PCA, you are taking the whole data and after that you are doing train test split. Isn't bit unethical? Again, if I do pca on train data, is same will the same pca can be applied on test data? Is there anyway to store the transformation of PCA to apply that on test data?
@hrithiksarma1204
@hrithiksarma1204 2 года назад
I had the same doubt, have you got any update on this ?
@sharmilasenguptachowdhry509
@sharmilasenguptachowdhry509 2 года назад
Thanks v m! can you pls help explain Eigen values and Eigen vectors from the data science perspective? thanks again
@mayank66
@mayank66 11 месяцев назад
amajing
@MyManiratnam
@MyManiratnam 2 года назад
Hi, I have seen your videos on PCA they are really informative and your explanation is really cool. I have a doubt, we apply PCA on the dataset and later we go for model fitting for example if it is a classification problem we go for classification model. Here my doubt is, after building a model we validate it with test set, after that if I have new observation i.e new row in the dataset, how to predict my label?
@kirubakaran6145
@kirubakaran6145 6 месяцев назад
hello Maniratnam, have you got the answer the above question?.
@namantiwari8251
@namantiwari8251 Год назад
Sir can you please tell which features it reduces How can I get those particular selected (reduced) features as output?
@user-ek1tb4yq9s
@user-ek1tb4yq9s 5 месяцев назад
I have a query to ask. You said we should pass the data to PCA after scaling but you passed the original X instead of X_scaled. Why ??
@zainnaveed267
@zainnaveed267 2 года назад
sir i have a question how one can predict target values when PCA create all new columns based on its own calculations
@ahsanurrahman8915
@ahsanurrahman8915 11 месяцев назад
Very nicely described ! I have a question: In your example PCA(0.95) reduces the dimension to 29. But, how do we know which dimensions it picked? I am asking this because I want to use PCA to determine the principal drivers in determining the targets.
@akashbhargava906
@akashbhargava906 6 месяцев назад
hey buddy, PCA doesn't pick any existing dimension. It creates new dimensions which by the naked eye won't make much sense to you.
@ogochukwustanleyikegbo2420
@ogochukwustanleyikegbo2420 10 месяцев назад
After completing the assignment, i got a best score of 0.85 with svm:rbf kernel and after PCA my best score reduced to 0.68 still svm:rbf kernel
@nikhilanand9022
@nikhilanand9022 Год назад
Here is my two question for u 1- why u dont scaled the target column means (y) 2- for score as accuracy why u dont compare with actual and predicted u give for score is x_test and y_test why not y_pred and y_test
@gulnawaz9670
@gulnawaz9670 2 года назад
Hi Sir, very informative video. I have a problem I uploaded a local dataset and when I use code dataset.keys () which shows Index(['Unnamed: 0', 'Flow ID', ............ Now at pd.DataFrame(dataset.data, columns=dataset.feature_names) then it shows an error even I changed data into Unnamed as well but ut occurs the same problem. AttributeError: 'DataFrame' object has no attribute 'data' waiting for your kind reply. Thanks.
@arjunprashanth7824
@arjunprashanth7824 2 месяца назад
Shouldn't X_scaled be passed inside pca.fit_transform() method? Because if you're passing X, there's no point we did the scaling right?
@AnasAhmadKhan-me7ur
@AnasAhmadKhan-me7ur 20 дней назад
Exactly, i was about to ask the same question.
@user-jh4wo6ok4s
@user-jh4wo6ok4s 14 дней назад
I tried both. When passing X to pca without scaling, I got higher score. But you're right, I also believe to pass X_scaled for parallel comparison.
@RamveerSingh-el6zl
@RamveerSingh-el6zl 8 месяцев назад
Can you tell how to do varimax rotation?
@krishnapatel8852
@krishnapatel8852 Год назад
hello, if I want to visulize this data in 3D, then what will be z axis ?
@farahamirah2091
@farahamirah2091 Год назад
I have question, we can trained model using pca , then how about imbalance dataset? We not need to do imbalance?
@pateltapasvi7277
@pateltapasvi7277 6 месяцев назад
How can I get selected features in dataframe along with its feature name instead of number 1, 2, 3,etc.?
@BG4INDIA
@BG4INDIA Год назад
Hi Mr. Dhaval, I am so thankful for sharing such a good informative video. Like "ogobuchiokey2978" even i wanted to know, if there is a specific reason of not selecting X_scaled while fitting into PCA? In the above demo, if I fit raw X, I get 29 new PCA-features but if i fit scaled_X i get new 40 PCA-features. Similarly through your exercise, if I fit scaled_X I get 10 features (only 1 attribute is reduced) with Accuracy of 85% and if i fit raw X, i get 2 attributes, but accuracy dips down to 69%(Random Forest) I believe this depends on the data as well.
@vtechguruG
@vtechguruG Год назад
hello! i am confused about scaling of data before pca...what should i do if we have 20% categorical feature in my dataset?do i need to scale them?
@mohamedgad9429
@mohamedgad9429 11 месяцев назад
i think you should apply 1 hot encdoding first
@Cat_Sterling
@Cat_Sterling Год назад
Should you scale the data before PCA?
@VickyKumar-dk6rd
@VickyKumar-dk6rd 2 года назад
feature_names column is now not reflecting in Load_digits() dataset
@einnairo
@einnairo Год назад
I have a question. After going through scaling, and then PCA, the features are now all different to the original of values between 0 and 16. When I have a new digit to classify and been provided with the same 64 features, how do I make this new prediction?
@ogochukwustanleyikegbo2420
@ogochukwustanleyikegbo2420 10 месяцев назад
You have to scale the new digit and apply PCA to it before classification
@kalluriyaswanthkumar2275
@kalluriyaswanthkumar2275 Год назад
sir you told that we should scale before pca but you are applying pca to non scaled data in code
@ajaxx627
@ajaxx627 2 года назад
Please I have a problem with some work. I was given a list of words let’s say about 200 different words. And I’m meant to create a code that generates 3 random words each together. Eg wordlist=[a, b, c, d, e,................z] Output should be = a, d, z c, o, x And so on Please how do I do it?
@taimoorneutron2940
@taimoorneutron2940 2 года назад
hello sir, i am 27 now and masters is in progress sir i have teaching experience. but now i want to start my career in Machine learning or data science ? so it is possible? every company needs new fresh comers so what should i do?
@girishtripathy3354
@girishtripathy3354 2 года назад
The dimensions it should get reduced to, isn't it another hyper parameter? For 2 dimensions yeah you can visualize. For > 2, visualization is not possible. How can you decide what dimension you should reduce your dataset to?
@snehasneha9290
@snehasneha9290 2 года назад
After reducing the dimensions is it possible to know which columns are selected after applying the PCA in this example we got the 29 features is it possible to know what are those 29 out of total data frame features
@kunalchavan4685
@kunalchavan4685 Год назад
I am having the same question but I think this are not the same 29 columns out of 64, this are totally different 29 columns which contains data from all 64 columns
@yamrajoli3834
@yamrajoli3834 2 года назад
is this the completer ml course?
@amrutha46
@amrutha46 2 года назад
How do we know which columns got removed?
@bommubhavana8794
@bommubhavana8794 Год назад
Hello, I have newly started working on a PCR project. I am stuck at a point and could really use some help...asap Thanks a lot in advance. I am working on python. So we have created PCA instance using PCA(0.85) and transformed the input data. We have run a regression on principal components explaining 85 percent variance(Say N components). Now we have a regression equation in terms of N PCs. We have taken this equation and tried to express it in terms of original variables. Now, In order to QC the coefficients in terms of original variables, we tried to take the N components(85% variance) and derived the new data back from this, and applied regression on this data hoping that this should give the same coefficients and intercept as in the above derived regression equation. The issue here is that the coefficients are not matching when we take N components but when we take all the components the coefficients and intercept are matching exactly. Also, R squared value and the predictions provided by these two equations are exactly same even if the coefficients are not matching I am soo confused right now as to why this is happening. I might be missing out on the concept of PCA at some point. Any help is greatly appreciated.Thank you!
@kudimaysey2459
@kudimaysey2459 2 года назад
Nice job. Thanks
@MonilModi10
@MonilModi10 Год назад
Why PCA rotate the axis? What is a significance of that?
@wangjessica1275
@wangjessica1275 3 месяца назад
How to interpret PCA result in regression?
@ridoychandraray2413
@ridoychandraray2413 Год назад
How to see which columns are this?
@BlackDragon-gd6io
@BlackDragon-gd6io 2 года назад
Sir, I did all the things in exercise. I have a question. If I did the PCA, I'm loosing the feature names. How do I get back them?
@r0cketRacoon
@r0cketRacoon 3 месяца назад
have u figured the answer? in my opinion, columns created from PCA are new so it is unnecessary to know the feature names.
Далее
PCA Analysis in Python Explained (Scikit - Learn)
16:11
КРАФЧУ NAMELESS СКИН!
1:53:35
Просмотров 453 тыс.
Principal Component Analysis (PCA)
6:28
Просмотров 190 тыс.
Principal Component Analysis (PCA)
13:46
Просмотров 364 тыс.
КРАФЧУ NAMELESS СКИН!
1:53:35
Просмотров 453 тыс.