research / lrt /utils /dimension_reduction.py
haoqi7's picture
Upload 47 files
16188ba
raw
history blame contribute delete
No virus
515 Bytes
from sklearn.decomposition import PCA as pca
class BaseDimensionReduction:
def dimension_reduction(self,X):
raise NotImplementedError()
class PCA(BaseDimensionReduction):
def __init__(self, n_components: int = 0.8, *args, **kwargs) -> None:
super().__init__()
self.pca = pca(n_components,*args,**kwargs)
def dimension_reduction(self, X):
self.pca.fit(X=X)
print(f'>>> The reduced dimension is {self.pca.n_components_}.')
return self.pca.transform(X)