8000 COSMIT + DOC input handling and docstrings in RandomizedPCA · scikit-learn/scikit-learn@1426087 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1426087

Browse files
committed
COSMIT + DOC input handling and docstrings in RandomizedPCA
1 parent 38c3c30 commit 1426087

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

sklearn/decomposition/pca.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -456,13 +456,11 @@ def fit(self, X, y=None):
456456
self.random_state = check_random_state(self.random_state)
457457
if not hasattr(X, 'todense'):
458458
# not a sparse matrix, ensure this is a 2D array
459-
X = array2d(X)
459+
X = np.atleast_2d(as_float_array(X, copy=self.copy))
460460

461461
n_samples = X.shape[0]
462462

463463
if not hasattr(X, 'todense'):
464-
X = as_float_array(X, copy=self.copy)
465-
466464
# Center data
467465
self.mean_ = np.mean(X, axis=0)
468466
X -= self.mean_
@@ -475,9 +473,8 @@ def fit(self, X, y=None):
475473
n_iterations=self.iterated_power,
476474
random_state=self.random_state)
477475

478-
self.explained_variance_ = (S ** 2) / n_samples
479-
self.explained_variance_ratio_ = self.explained_variance_ / \
480-
self.explained_variance_.sum()
476+
self.explained_variance_ = exp_var = (S ** 2) / n_samples
477+
self.explained_variance_ratio_ = exp_var / exp_var.sum()
481478

482479
if self.whiten:
483480
n = X.shape[0]
@@ -488,7 +485,7 @@ def fit(self, X, y=None):
488485
return self
489486

490487
def transform(self, X):
491-
"""Apply the dimensionality reduction on X.
488+
"""Apply dimensionality reduction on X.
492489
493490
Parameters
494491
----------
@@ -508,8 +505,9 @@ def transform(self, X):
508505
return X
509506

510507
def inverse_transform(self, X):
511-
"""Transform data back to its original space, i.e.,
512-
return an input X_original whose transform would be X
508+
"""Transform data back to its original space.
509+
510+
Returns an array X_original whose transform would be X.
513511
514512
Parameters
515513
----------
@@ -524,7 +522,7 @@ def inverse_transform(self, X):
524522
Notes
525523
-----
526524
If whitening is enabled, inverse_transform does not compute the
527-
exact inverse operation as transform.
525+
exact inverse operation of transform.
528526
"""
529527
X_original = safe_sparse_dot(X, self.components_)
530528
if self.mean_ is not None:

0 commit comments

Comments
 (0)
0