def pca_preprocessing(data, n_components, normalize): projector = PCA(n_components=n_components, random_state=0) if normalize: projector.preprocessors += (preprocess.Normalize(),) model = projector(data) return model(data)
def fit(self): self.clear() self.Warning.trivial_components.clear() if self.data is None: return data = self.data if self.normalize: self._pca_projector.preprocessors = \ self._pca_preprocessors + [preprocess.Normalize(center=False)] else: self._pca_projector.preprocessors = self._pca_preprocessors if not isinstance(data, SqlTable): pca = self._pca_projector(data) variance_ratio = pca.explained_variance_ratio_ cumulative = numpy.cumsum(variance_ratio) if numpy.isfinite(cumulative[-1]): self.components_spin.setRange(0, len(cumulative)) self._pca = pca self._variance_ratio = variance_ratio self._cumulative = cumulative self._setup_plot() else: self.Warning.trivial_components() self.unconditional_commit()
def pca_preprocessing(self): """Perform PCA preprocessing before passing off the data to t-SNE.""" if self.pca_data is not None: return projector = PCA(n_components=self.pca_components, random_state=0) # If the normalization box is ticked, we'll add the `Normalize` # preprocessor to PCA if self.normalize: projector.preprocessors += (preprocess.Normalize(),) model = projector(self.data) self.pca_data = model(self.data)