def transform(self, predictors, **kwargs): result = [] id = 0 for location in self.locations: raw = extract_n_by_n(predictors, location, **kwargs) result.append(self.pcas[id].transform(raw)) id += 1 return result
def fit(self, predictors, locations, **kwargs): self.locations = locations self.pcas = [] self.n = predictors['n'] for location in locations: raw = extract_n_by_n(predictors, location, **kwargs) #pca = PCA(n_components='mle', whiten=True) #pca = PCA(n_components=0.95, whiten=True) pca = PCA(n_components=2) pca = pca.fit(raw) components = pca.components_ pca.components_ = components self.pcas.append(pca.fit(raw)) print "pca: ", location, pca.n_components_, pca.explained_variance_ratio_