principal component analysis (pcapcagenerally called data reduction techniqueis very useful feature selection technique as it uses linear algebra to transform the dataset into compressed form we can implement pca feature selection technique with the help of pca class of scikit-learn python library we can select number of principal components in the output examplein this examplewe will use pca to select best principal components from pima indians diabetes dataset from pandas import read_csv from sklearn decomposition import pca path ' :\pima-indians-diabetes csvnames ['preg''plas''pres''skin''test''mass''pedi''age''class'dataframe read_csv(pathnames=namesarray dataframe values nextwe will separate array into input and output componentsx array[:, : array[:, the following lines of code will extract features from datasetpca pca(n_components= fit pca fit(xprint("explained variance% "fit explained_variance_ratio_ print(fit components_output explained variance [- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ]