Mở đầu.
Bạn đang xem: Principal component analysis là gì
Đây là thuật toán sinh ra để giải quyết vấn đề dữ liệu có quá nhiều chiều dữ liệu, cần giảm bớt chiều dữ liệu nhằm tăng tốc độ xử lí, nhưng vẫn giữ lại thông tin nhiều nhất có thể (high variance).
Chúng ta cần tìm ra chiều dữ liệu có độ quan trọng cao, nhằm giảm bớt việc tính toán, cũng như tăng tốc độ xử lí.
PCA chuyển dữ liệu từ linear thành các thuộc tính mới không liên quan lẫn nhau.
Xem thêm: Lỗi Màn Hình Xanh (bsod): Nguyên Nhân & 8 Cách Sửa Lỗi Màn Hình Xanh
Dữ liệu.
Chúng ta cần phân biệt 2 loại dữ liệu:
Dữ liệu liên quan (correlated):
Dữ liệu không liên quan (uncorrelated):
PCA tìm ra mean và principal components.
Xem thêm: Android One Là Gì – Tìm Hiểu Về Android One
Làm thế nào để implement PCA:
Biến đổi X về dạng đồng nhất.Tính toán covariance matrix ΣTìm eigenvectors của ΣLấy K dimensions có giá trị variance cao nhất
eigenvectors (vector màu đỏ)
là vector không thay đổi hướng khi apply linear transformation.
eigenvalue cho PC1
eigenvalue cho PC2
eigenvector
Sự phân bổ độ quan trọng của chiều dữ liệu
Algorithm
from numpy import arrayfrom numpy import meanfrom numpy import covfrom numpy.linalg import eig# define a matrixA = array(, , >)print(A)# calculate the mean of each columnM = mean(A.T, axis=1)print(M)# center columns by subtracting column meansC = A – Mprint(C)# calculate covariance matrix of centered matrixV = cov(C.T)print(V)# eigendecomposition of covariance matrixvalues, vectors = eig(V)print(vectors)print(values)# project dataP = vectors.T.dot(C.T)print(P.T)Output:
Reference:
Chuyên mục: Hỏi Đáp