MCPcopy Create free account
hub / github.com/rushter/MLAlgorithms / _decompose

Method _decompose

mla/pca.py:39–55  ·  view source on GitHub ↗
(self, X)

Source from the content-addressed store, hash-verified

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()

Callers 1

fitMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected