Principal Component Analyis is basically a statistical procedure to convert a set of observation of possibly correlated variables into a set of values of linearly uncorrelated variables.
Each of the principal components is chosen in such a way so that it would describe most of the still available variance and all these principal components are orthogonal to each other. In all principal components first principal component has maximum variance.
Uses of PCA:
- It is used to find inter-relation between variables in the data.
- It is used to interpret and visualize data.
- As number of variables are decreasing it makes further analysis simpler.
- It’s often used to visualize genetic distance and relatedness between populations.
These are basically performed on square symmetric matrix. It can be a pure sums of squares and cross products matrix or Covariance matrix or Correlation matrix. A correlation matrix is used if the individual variance differs much.
Objectives of PCA:
- It is basically a non-dependent procedure in which it reduces attribute space from a large number of variables to a smaller number of factors.
- PCA is basically a dimension reduction process but there is no guarantee that the dimension is interpretable.
- Main task in this PCA is to select a subset of variables from a larger set, based on which original variables have the highest correlation with the principal amount.
Principal Axis Method: PCA basically search a linear combination of variables so that we can extract maximum variance from the variables. Once this process completes it removes it and search for another linear combination which gives an explanation about the maximum proportion of remaining variance which basically leads to orthogonal factors. In this method, we analyze total variance.
Eigenvector: It is a non-zero vector that stays parallel after matrix multiplication. Let’s suppose x is eigen vector of dimension r of matrix M with dimension r*r if Mx and x are parallel. Then we need to solve Mx=Ax where both x and A are unknown to get eigen vector and eigen values.
Under Eigen-Vectors we can say that Principal components show both common and unique variance of the variable. Basically, it is variance focused approach seeking to reproduce total variance and correlation with all components. The principal components are basically the linear combinations of the original variables weighted by their contribution to explain the variance in a particular orthogonal dimension.
Eigen Values: It is basically known as characteristic roots. It basically measures the variance in all variables which is accounted for by that factor. The ratio of eigenvalues is the ratio of explanatory importance of the factors with respect to the variables. If the factor is low then it is contributing less in explanation of variables. In simple words, it measures the amount of variance in the total given database accounted by the factor. We can calculate the factor’s eigen value as the sum of its squared factor loading for all the variables.
Now, Let’s understand Principal Component Analysis with Python.
To get the dataset used in the implementation, click here.
Step 1: Importing the libraries
Step 2: Importing the data set
Import the dataset and distributing the dataset into X and y components for data analysis.
Step 3: Splitting the dataset into the Training set and Test set
Step 4: Feature Scaling
Doing the pre-processing part on training and testing set such as fitting the Standard scale.
Step 5: Applying PCA function
Applying the PCA function into training and testing set for analysis.
Step 6: Fitting Logistic Regression To the training set
Step 7: Predicting the test set result
Step 8: Making the confusion matrix
Step 9: Predicting the training set result
Step 10: Visualising the Test set results
- Python - Variations of Principal Component Analysis
- ML | Principal Component Analysis(PCA)
- ML | Independent Component Analysis
- Text Analysis in Python 3
- Python | NLP analysis of Restaurant reviews
- Data Analysis and Visualization with Python | Set 2
- Python | Sentiment Analysis using VADER
- Exploratory Data Analysis in Python
- Data analysis and Visualization with Python
- Twitter Sentiment Analysis using Python
- Facebook Sentiment Analysis using python
- Exploratory Data Analysis in Python | Set 2
- Exploratory Data Analysis in Python | Set 1
- Python | Data analysis using Pandas
- Multidimensional data analysis in Python
- Python | CAP - Cumulative Accuracy Profile analysis
- Python | Math operations for Data analysis
- Python | Customer Churn Analysis Prediction
- Analysis of Different Methods to find Prime Number in Python
- Analysis of test data using K-Means Clustering in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.