Skip to content

Commit 5954ffa

Browse files
committed
Add comment regarding PCA's fit_transform method.
1 parent 8d4e32a commit 5954ffa

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

scikits/learn/pca.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,10 @@ def fit_transform(self, X, y=None, **params):
202202
U = U[:, :self.n_components]
203203

204204
if self.whiten:
205+
# X_new = X * V / S * sqrt(n_samples) = U * sqrt(n_samples)
205206
U *= np.sqrt(X.shape[0])
206207
else:
208+
# X_new = X * V = U * S * V^T * V = U * S
207209
U *= S[:self.n_components]
208210

209211
return U
@@ -223,8 +225,7 @@ def _fit(self, X, **params):
223225
self.explained_variance_.sum()
224226

225227
if self.whiten:
226-
n = X.shape[0]
227-
self.components_ = V.T / S * np.sqrt(n)
228+
self.components_ = V.T / S * np.sqrt(n_samples)
228229
else:
229230
self.components_ = V.T
230231

0 commit comments

Comments
 (0)