class sklearn.decomposition.IncrementalPCA(n_components=None, whiten=False, copy=True, batch_size=None)
[source]
Incremental principal components analysis (IPCA).
Linear dimensionality reduction using Singular Value Decomposition of centered data, keeping only the most significant singular vectors to project the data to a lower dimensional space.
Depending on the size of the input data, this algorithm can be much more memory efficient than a PCA.
This algorithm has constant memory complexity, on the order of batch_size
, enabling use of np.memmap files without loading the entire file into memory.
The computational overhead of each SVD is O(batch_size * n_features ** 2)
, but only 2 * batch_size samples remain in memory at a time. There will be n_samples / batch_size
SVD computations to get the principal components, versus 1 large SVD of complexity O(n_samples * n_features ** 2)
for PCA.
Read more in the User Guide.
Parameters: 


Attributes: 

See also
Implements the incremental PCA model from: D. Ross, J. Lim, R. Lin, M. Yang, Incremental Learning for Robust Visual Tracking, International Journal of Computer Vision, Volume 77, Issue 13, pp. 125141, May 2008.
See http://www.cs.toronto.edu/~dross/ivt/RossLimLinYang_ijcv.pdf
This model is an extension of the Sequential KarhunenLoeve Transform from: A. Levy and M. Lindenbaum, Sequential KarhunenLoeve Basis Extraction and its Application to Images, IEEE Transactions on Image Processing, Volume 9, Number 8, pp. 13711374, August 2000.
See http://www.cs.technion.ac.il/~mic/doc/sklip.pdf
We have specifically abstained from an optimization used by authors of both papers, a QR decomposition used in specific situations to reduce the algorithmic complexity of the SVD. The source for this technique is Matrix Computations, Third Edition, G. Holub and C. Van Loan, Chapter 5, section 5.4.4, pp 252253.
. This technique has been omitted because it is advantageous only when decomposing a matrix with n_samples
(rows) >= 5/3 * n_features
(columns), and hurts the readability of the implemented algorithm. This would be a good opportunity for future optimization, if it is deemed necessary.
>>> from sklearn.datasets import load_digits >>> from sklearn.decomposition import IncrementalPCA >>> X, _ = load_digits(return_X_y=True) >>> transformer = IncrementalPCA(n_components=7, batch_size=200) >>> # either partially fit on smaller batches of data >>> transformer.partial_fit(X[:100, :]) IncrementalPCA(batch_size=200, copy=True, n_components=7, whiten=False) >>> # or let the fit function itself divide the data into batches >>> X_transformed = transformer.fit_transform(X) >>> X_transformed.shape (1797, 7)
fit (X[, y])  Fit the model with X, using minibatches of size batch_size. 
fit_transform (X[, y])  Fit to data, then transform it. 
get_covariance ()  Compute data covariance with the generative model. 
get_params ([deep])  Get parameters for this estimator. 
get_precision ()  Compute data precision matrix with the generative model. 
inverse_transform (X)  Transform data back to its original space. 
partial_fit (X[, y, check_input])  Incremental fit with X. 
set_params (**params)  Set the parameters of this estimator. 
transform (X)  Apply dimensionality reduction to X. 
__init__(n_components=None, whiten=False, copy=True, batch_size=None)
[source]
fit(X, y=None)
[source]
Fit the model with X, using minibatches of size batch_size.
Parameters: 


Returns: 

fit_transform(X, y=None, **fit_params)
[source]
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
Parameters: 


Returns: 

get_covariance()
[source]
Compute data covariance with the generative model.
cov = components_.T * S**2 * components_ + sigma2 * eye(n_features)
where S**2 contains the explained variances, and sigma2 contains the noise variances.
Returns: 


get_params(deep=True)
[source]
Get parameters for this estimator.
Parameters: 


Returns: 

get_precision()
[source]
Compute data precision matrix with the generative model.
Equals the inverse of the covariance but computed with the matrix inversion lemma for efficiency.
Returns: 


inverse_transform(X)
[source]
Transform data back to its original space.
In other words, return an input X_original whose transform would be X.
Parameters: 


Returns: 

If whitening is enabled, inverse_transform will compute the exact inverse operation, which includes reversing whitening.
partial_fit(X, y=None, check_input=True)
[source]
Incremental fit with X. All of X is processed as a single batch.
Parameters: 


Returns: 

set_params(**params)
[source]
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter>
so that it’s possible to update each component of a nested object.
Returns: 


transform(X)
[source]
Apply dimensionality reduction to X.
X is projected on the first principal components previously extracted from a training set.
Parameters: 


Returns: 

>>> import numpy as np >>> from sklearn.decomposition import IncrementalPCA >>> X = np.array([[1, 1], [2, 1], [3, 2], [1, 1], [2, 1], [3, 2]]) >>> ipca = IncrementalPCA(n_components=2, batch_size=3) >>> ipca.fit(X) IncrementalPCA(batch_size=3, copy=True, n_components=2, whiten=False) >>> ipca.transform(X)
sklearn.decomposition.IncrementalPCA
© 2007–2018 The scikitlearn developers
Licensed under the 3clause BSD License.
http://scikitlearn.org/stable/modules/generated/sklearn.decomposition.IncrementalPCA.html