here i have tried to perform pca on my dataset but i dont have any idea how to get the important features and eleminate the feature which is not selected. here i have given a condition that if data contains more than 10 features then perform PCA else dont perform PCA.
from sklearn.decomposition import PCA
from sklearn import preprocessing
columns = x.columns
def Perform_PCA(x):
no_of_col = len(x.columns)
percent = 90
my_num = int((percent/100)*no_of_col)
if no_of_col >= 10:
pca = PCA(n_components = my_num)
x_new = pca.fit_transform(x)
print("More than 10 columns found Performing PCA")
return selected_var
else:
print("Less than 10 columns found no PCA performed")
return x
x = Perform_PCA(x)
x