@@ -456,13 +456,11 @@ def fit(self, X, y=None):
456
456
self .random_state = check_random_state (self .random_state )
457
457
if not hasattr (X , 'todense' ):
458
458
# 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 ) )
460
460
461
461
n_samples = X .shape [0 ]
462
462
463
463
if not hasattr (X , 'todense' ):
464
- X = as_float_array (X , copy = self .copy )
465
-
466
464
# Center data
467
465
self .mean_ = np .mean (X , axis = 0 )
468
466
X -= self .mean_
@@ -475,9 +473,8 @@ def fit(self, X, y=None):
475
473
n_iterations = self .iterated_power ,
476
474
random_state = self .random_state )
477
475
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 ()
481
478
482
479
if self .whiten :
483
480
n = X .shape [0 ]
@@ -488,7 +485,7 @@ def fit(self, X, y=None):
488
485
return self
489
486
490
487
def transform (self , X ):
491
- """Apply the dimensionality reduction on X.
488
+ """Apply dimensionality reduction on X.
492
489
493
490
Parameters
494
491
----------
@@ -508,8 +505,9 @@ def transform(self, X):
508
505
return X
509
506
510
507
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.
513
511
514
512
Parameters
515
513
----------
@@ -524,7 +522,7 @@ def inverse_transform(self, X):
524
522
Notes
525
523
-----
526
524
If whitening is enabled, inverse_transform does not compute the
527
- exact inverse operation as transform.
525
+ exact inverse operation of transform.
528
526
"""
529
527
X_original = safe_sparse_dot (X , self .components_ )
530
528
if self .mean_ is not None :
0 commit comments