PCA降维(二)
下面是我实现的PCA代码,有不足之处还请指正 import numpy as np from sklearn . decomposition import PCA from sklearn . linear_model import LogisticRegression ''' define class myPCA ''' class myPCA : ''' Initialize function of class myPCA. Input: n_components:The dimension after dimensionality reduction if n_components=0, n_components will be set by the refactoring threshold t: threshold, t=0.95 ''' def __init__ ( self , n_components = 0 , t = 0.95 ) : self . n_components = n_components self . t = t self . w = [ ] self . mean_x = [ ] ''' define get_mean_X function. Input: X:numpy.ndarry, size: [num_sample, num