+15 XP
PCA: Finding the Signal
PCA (Principal Component Analysis) finds the directions of maximum variance in high-dimensional data, letting you visualize 100 neurons in just 2 dimensions.
The key idea: neurons are correlated. 100 neurons don't give 100 independent dimensions of information. PCA finds the few directions that explain most of the variance β these are the principal components.
python
import numpy as np
from sklearn.decomposition import PCA
# Neural data: 200 trials Γ 100 neurons
data = np.random.randn(200, 100)
# Reduce to 2 dimensions
pca = PCA(n_components=2)
data_2d = pca.fit_transform(data)
print(data_2d.shape) # (200, 2)
print(pca.explained_variance_ratio_) # % variance each PC capturessklearn PCA β the NMA way to visualize neural population activity.
Explained variance tells you how much information each PC captures. If PC1 explains 40% of variance and PC2 explains 25%, your 2D plot captures 65% of the signal.
π¦ Ilya says: NMA W1D4 is all about PCA on neural data. You'll make the exact plots that appear in top neuroscience papers!