Hi all,

I need to run a PCA analysis on a microarray dataset to estimate which are the most relevant features. How can I do it? Is it possible?

I tried with `scikit-learn` but I was unable to come with the relevant genes. I did it like this:

    from sklearn.decomposition import PCA
    import numpy as np
    
    # X is the matrix transposed (n samples on the rows, m features on the columns) - it is represented as a numpy array
    X = np.array([[-1, -2, 5, 1], [-3, -1, 1, 0], [-3, -2, 0, 2], [1, 1, 1, 3], [2, 1, 1, 4], [3, 2, 0, 5]])
    
    # suppose we want the 2 most relevant features
    nf = 2
    pca = PCA(n_components=nf)
    pca.fit(X)
    
    X_proj = pca.transform(X) 

With `X`

    array([[-1, -2,  5,  1],
           [-3, -1,  1,  0],
           [-3, -2,  0,  2],
           [ 1,  1,  1,  3],
           [ 2,  1,  1,  4],
           [ 3,  2,  0,  5]])

it returns `X_proj`

    array([[-2.9999967 ,  3.26498171],
           [-3.53939268, -1.18864266],
           [-2.77013188, -2.15637734],
           [ 1.67612209,  0.03059917],
           [ 2.87464655,  0.35674472],
           [ 4.75875261, -0.30730559]])

How can I say which are the selected features? Is there another way to do it (also in R for example)?

Thanks
Hi,

be careful because I think you are making some confusion about the concept of "components" in PCA.

The PCA doesn't return you the most relevant "features" in the dataset; it rather returns two vectors (or more, depending on how many components you calculate), corresponding to the coordinates of each element on a plane that divides the datasets into two parts. For a quick explanation of how PCA works, you can read this <a href="http://sorana.academicdirect.ro/pages/collagen/amino_acids/materials/PCA_1.pdf">document</a> or <a href="http://www.nature.com/nbt/journal/v26/n3/full/nbt0308-303.html">this article on Nature Biotechnology</a>.

If you want to determine how much each of your original variables contribute to the components, you can either look at the loadings of the pca (I can't install scikit right now, but it may be inside the pca object), or you can calculate the correlation of each variable with each of the components, like described <a href="https://onlinecourses.science.psu.edu/stat505/node/54">here</a>. This should give you an idea of the "relevant" features, the features that contribute the most to divide the data into two.

Another tool to do PCA with python is <a href="http://orange.biolab.si/docs/latest/widgets/rst/unsupervized/PCA/#pca">orange</a>, which gives you both a graphical interface (if you want to use it), and a python library.