| 37 | self._decompose(X) |
| 38 | |
| 39 | def _decompose(self, X): |
| 40 | # Mean centering |
| 41 | X = X.copy() |
| 42 | X -= self.mean |
| 43 | |
| 44 | if self.solver == "svd": |
| 45 | _, s, Vh = svd(X, full_matrices=True) |
| 46 | elif self.solver == "eigen": |
| 47 | s, Vh = np.linalg.eig(np.cov(X.T)) |
| 48 | Vh = Vh.T |
| 49 | |
| 50 | s_squared = s**2 |
| 51 | variance_ratio = s_squared / s_squared.sum() |
| 52 | logging.info( |
| 53 | "Explained variance ratio: %s" % (variance_ratio[0 : self.n_components]) |
| 54 | ) |
| 55 | self.components = Vh[0 : self.n_components] |
| 56 | |
| 57 | def transform(self, X): |
| 58 | X = X.copy() |