Principal Component Analysis Applications
Assignment
Introduction
PCA (Principal Component Analysis) is a dimensionality reduction technique used in machine learning
and statistics. It transforms correlated variables into a smaller number of uncorrelated variables called
principal components while retaining maximum variance. It is widely used for visualization,
compression, noise removal, and improving model performance.
Problem 1: Medical Imaging (MRI Tumor Detection)
Goal: Reduce 200 correlated MRI features, retain 95% variance, and compare classification accuracy
before and after PCA.
from [Link] import StandardScaler
from [Link] import PCA
from [Link] import SVC
from sklearn.model_selection import train_test_split
from [Link] import accuracy_score
import pandas as pd
data = pd.read_csv("mri_data.csv")
X = [Link]("label",axis=1)
y = data["label"]
X = StandardScaler().fit_transform(X)
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2)
model=SVC()
[Link](X_train,y_train)
print("Accuracy Before PCA:",accuracy_score(y_test,[Link](X_test)))
pca=PCA(0.95)
X_pca=pca.fit_transform(X)
X_train,X_test,y_train,y_test=train_test_split(X_pca,y,test_size=0.2)
[Link](X_train,y_train)
print("Accuracy After PCA:",accuracy_score(y_test,[Link](X_test)))
Explanation
PCA removes correlated medical features and noise, improving classification speed and generalization
performance.
Problem 3: Stock Market Analysis
Goal: Reduce 50 stock variables into 2 principal components and interpret market factors.
import pandas as pd
import numpy as np
from [Link] import PCA
import [Link] as plt
data=pd.read_csv("[Link]")
pca=PCA(n_components=2)
pc=pca.fit_transform(data)
[Link](pc[:,0],pc[:,1])
[Link]("PC1")
[Link]("PC2")
[Link]()
Interpretation
PC1 represents overall market trend affecting most stocks. PC2 represents sector■wise variation or
deviations from market trend.
Problem 4: Face Recognition (Eigenfaces)
Goal: Reduce 4096 image features into 50 components and reconstruct faces.
import numpy as np
from [Link] import PCA
faces=[Link]("[Link]")
pca=PCA(n_components=50)
reduced=pca.fit_transform(faces)
reconstructed=pca.inverse_transform(reduced)
error=[Link]((faces-reconstructed)**2)
print("Reconstruction Error:",error)
Explanation
Eigenfaces are principal components of facial images. PCA captures major facial patterns and removes
redundant pixel information.
Problem 6: Customer Segmentation
Goal: Reduce 25 customer features to 2 dimensions and perform clustering.
from [Link] import StandardScaler
from [Link] import PCA
from [Link] import KMeans
import pandas as pd
data=pd.read_csv("[Link]")
scaled=StandardScaler().fit_transform(data)
X=PCA(n_components=2).fit_transform(scaled)
labels=KMeans(n_clusters=3).fit_predict(X)
Interpretation
Clusters represent customer groups such as high spenders, budget buyers, and occasional shoppers.
Businesses use this for targeted marketing.
Conclusion
PCA is a powerful dimensionality reduction technique useful across domains such as healthcare,
finance, image processing, and business analytics. It improves visualization, reduces computational
cost, removes redundancy, and often improves machine learning performance. This assignment
demonstrated real■world applications of PCA in multiple industries.