Understanding PCA for Dimensionality Reduction
Learn the basics of Principal Component Analysis (PCA).
- Standardize data:
def standardize(data):
mean = sum(data) / len(data)
std = (sum((x-mean)**2 for x in data) / len(data)) ** 0.5
return [(x-mean)/std for x in data]
- Calculate covariance matrix:
def covariance_matrix(data):
n = len(data[0])
return [[sum(data[i][k]*data[j][k] for k in range(n)) for j in range(n)] for i in range(n)]
Read more: PCA Algorithm