Namaskar, I am (name) from learnvern. (6 seconds pause, music)
In the continuation to the last session on machine learning we will further learn in this session. In today’s session we are going to watch PCA which we have already understood conceptually.Principal Component Analysis.
So how we implement principal component analysis using SK learn library, that I will explain to you. So first of all we will import, import numpy (pronounce - numph - pie) as np, then after this we will from SK learn package, so from sklearn dot decomposition, so this I will connect so that I start getting suggestions , so decomposition import PCA . So here numpy as np we have imported, and from SK learning dot decomposition we will get PCA.. So let’s now take some sample data as we have previously also done , X is equal to np dot A R R A Y array, dot array and let’s take a list here and inside this our multiple lists will be there, like -1comma -1, this is one dataset , comma next, this one data point, next data point we will keep as -2 comma -1 and next data point we will keep here is -3 comma -2, this we will keep and control Z , yes , and after this let’s take one more element and this element we will keep as, we will give positive value 1 comma 1 and next value you can keep 2 comma 1 and after this let’s take one more value of 3 comma 2 , so 3 comma 2. So these many values we have taken and this is our X, OK. Now if you see you observe that there is one one , then minus one minus one , then minus three minus two, so what we have to do here is decompose them , decompose them meaning lowering down in dimensions. So, let’s see how we will do this, so PCA we have imported and for that I will make an object or model , so pca equal to PCA in capitals and here how many number of components do we have, we have two number of components , so here you can see that minus one, one these are two components , so we have to decompose them, so OK, so the number of components are two and here you can read the description for it also , so what it is doing is SVD, Singular Value Decomposition and this we read in theory also, and understood that how it decomposes through SVD , and reduces dimensions, this we had seen.
OK so the number of components to keep here , so here we will keep two components that we are specifying here, so if it is not set then all components are kept means that if we do not set it then it will keep all components. So, let’s go ahead and execute it , PCA becomes my object or model of PCA.. Now whatever methods we have been using till now, the same methods will be used here , and it’s name is fit so with fit model I will feed my data here so I have passed X as an input here , so PCA dot fit and in that I have passed X . So now PCA has done its work because this is also an algorithm, a logic and it has already run the algorithm on X . So now here I should see that how much is the explained variance for this , OK , so explained variance is a term and this explained variance tells us that the more it is the more better it is , the more the explained variance the better it is because it distinctly tells the variation between the variance, isn’t it so the variation should be more and this is what we were trying in dimensionality reduction , that variance should be more. So here in explained variance what are the values that will come, let’s see , so pca dot explained variance , E X P L A I N E D explained variance, here it is , so what is the explained variance for this, so the explained variance for this you must be watching is that it is coming out to be , yes here it’s , this is 7.9 and it’s ratio we will just see , OK it’s coming out to be 7.9, 0.06 and explain variance we will just see , pca dot explained variance ratio ,.. OK, so this ratio we should get a little higher , so 0.99 OK, so 0.99 is quite good meaning 99% which is quite good , so, now let us see the value that we have got in PCA , that we will see pca dot singular values, ok, so here you can see these are the values we have got , so 6.3006 and 0.54, so, these are the values obtained after conversion.
So in this way you can convert data, I mean convert higher dimensional data into lower dimensional data and here you can pass as to how many dimensions you want so I had written two here so I got two, OK, you can change this also, you make it one and then execute it , and after executing you will see that you are getting a single value. So this is how you can reduce the dimensions, OK, this is how you can do that, OK so you apply this on any data set and after that in the new machine learning algorithm you can use that data set. So friends, today's session will end here and now we will continue in the next session.
If you have any queries or comments, click the discussion button below the video and post there. This way, you will be able to connect to fellow learners and discuss the course. Also, Our Team will try to solve your query.
Share a personalized message with your friends.