Hi Josh, thanks for the informative videos – they are very helpful. I

‘m trying to run the code but I’ve come across a head scratcher, I’m getting issues around this line:
pca_df = pd.DataFrame(pca_data, index=[*wt, *ko], columns=labels)

pca_data is a 100×10 vector, ie. the transformed version of scaled_data.

and so it doesn’t make sense for the rows/index to be the 10 samples as there are 100 rows???
Did you mean that this should be pca.components_ instead?

Would appreciate if you can clear up my confusion, much thanks!

In the example code, we start by making a matrix with 100 rows and 10 columns (100×10). The rows are “genes” and the columns are samples (thus, there are 100 genes, and 10 sample). This format is the standard format for genomic data (genes are rows, samples as columns). However, PCA functions almost always expect the samples to be rows and the “variables” (which are the “genes” in this case) to be columns. So when we scale the data we transpose it: scaled_data = preprocessing.scale(data.T)

As a result of passing “preprocessing.scale()” the transposed data, “scaled_data” is also transposed and we can pass this directly to pca.fit() without any more transposing. Does this make sense?

hi, thanks for sharing, it’s brilliant. i have a question about visualising more than 2 PCs. How can I plot 4 PCs? My spree plot suggest 4 PCs explains most of the variance in the my dataset. Can you please direct me how to visualise 4 PCs? Thanks.

Thank you for this great article, I have shared it on Facebook.

Thanks!

This is so very useful. Especially for people who are not computer scientists.Thank you very much.

You’re welcome! π

Hi Josh, thanks for the informative videos – they are very helpful. I

‘m trying to run the code but I’ve come across a head scratcher, I’m getting issues around this line:

pca_df = pd.DataFrame(pca_data, index=[*wt, *ko], columns=labels)

pca_data is a 100×10 vector, ie. the transformed version of scaled_data.

and so it doesn’t make sense for the rows/index to be the 10 samples as there are 100 rows???

Did you mean that this should be pca.components_ instead?

Would appreciate if you can clear up my confusion, much thanks!

In the example code, we start by making a matrix with 100 rows and 10 columns (100×10). The rows are “genes” and the columns are samples (thus, there are 100 genes, and 10 sample). This format is the standard format for genomic data (genes are rows, samples as columns). However, PCA functions almost always expect the samples to be rows and the “variables” (which are the “genes” in this case) to be columns. So when we scale the data we transpose it: scaled_data = preprocessing.scale(data.T)

As a result of passing “preprocessing.scale()” the transposed data, “scaled_data” is also transposed and we can pass this directly to pca.fit() without any more transposing. Does this make sense?

Ah yes, this makes sense now – thanks! π

hi, thanks for sharing, it’s brilliant. i have a question about visualising more than 2 PCs. How can I plot 4 PCs? My spree plot suggest 4 PCs explains most of the variance in the my dataset. Can you please direct me how to visualise 4 PCs? Thanks.

You can make a bunch of graphs, like PC1 against PC2, then PC1 agains PC2, then PC1 against PC3, then PC1 against PC4, then PC2 against PC3 etc.