spectrochempy.SVDο
- class SVD(**kwargs)[source]ο
- Singular Value Decomposition (SVD). - The SVD is commonly written as \(X = U \Sigma V^{T}\). - This class has the attributes : U, s = diag(S) and VT=V \(^T\). - If the dataset contains masked values, the corresponding ranges are ignored in the calculation. - Parameters:
- log_level (any of [ - "INFO",- "DEBUG",- "WARNING",- "ERROR"], optional, default:- "WARNING") β The log level at startup. It can be changed later on using the- set_log_levelmethod or by changing the- log_levelattribute.
- warm_start ( - bool, optional, default:- False) β When fitting repeatedly on the same dataset, but for multiple parameter values (such as to find the value maximizing performance), it may be possible to reuse previous model learned from the previous parameter value, saving time.- When - warm_startis- True, the existing fitted model attributes is used to initialize the new model in a subsequent call to- fit.
 
 - See also - EFA
- Perform an Evolving Factor Analysis (forward and reverse). 
- FastICA
- Perform Independent Component Analysis with a fast algorithm. 
- IRIS
- Integral inversion solver for spectroscopic data. 
- MCRALS
- Perform MCR-ALS of a dataset knowing the initial \(C\) or \(S^T\) matrix. 
- NMF
- Non-Negative Matrix Factorization. 
- PCA
- Perform Principal Components Analysis. 
- SIMPLISMA
- SIMPLe to use Interactive Self-modeling Mixture Analysis. 
 - Examples - >>> dataset = scp.read('irdata/nh4y-activation.spg') >>> svd = scp.SVD() >>> svd.fit(dataset) <svd: U(55, 55), s(55), VT(55, 5549)> >>> print(svd.ev.data) [1.185e+04 634 ... 0.001089 0.000975] >>> print(svd.ev_cum.data) [ 94.54 99.6 ... 100 100] >>> print(svd.ev_ratio.data) [ 94.54 5.059 ... 8.687e-06 7.779e-06] - Initialize the BaseConfigurable class. - Parameters:
- log_level (int, optional) β The log level at startup. Default is logging.WARNING. 
- **kwargs (dict) β Additional keyword arguments for configuration. 
 
 - Attributes Summary - Return the left unitary matrix. - Return a transpose matrix of the Loadings. - Return the X input dataset (eventually modified by the model). - The - Yinput.- NDDatasetwith components in feature space (n_components, n_features).- Whether or not to compute U and VT in addition to s. - traitlets.config.Configobject.- Return Cumulative Explained Variance. - Return a NDDataset of the explained variance. - Return Cumulative Explained Variance. - Return Explained Variance per singular values. - Return a NDDataset of the explained variance. - Return Explained Variance per singular values. - If False , U and VT have the shapes (M, k) and (k, N), respectively, where k = min(M, N). - Return - logoutput.- Number of components that were fitted. - Object name - Return Vector of singular values . - Return a NDDataset containing singular values. - Return a NDDataset containing singular values. - Methods Summary - fit(X)- Fit the SVD model on X. - fit_transform(X[,Β Y])- Fit the model with - Xand apply the dimensionality reduction on- X.- get_components([n_components])- Return the component's dataset: (selected n_components, n_features). - inverse_transform([X_transform])- Transform data back to its original space. - parameters([replace,Β removed,Β default])- Alias for - paramsmethod.- params([default])- Return current or default configuration values. - plotmerit([X,Β X_hat])- Plot the input ( - X), reconstructed (- X_hat) and residuals.- reconstruct([X_transform])- Transform data back to its original space. - reduce([X])- Apply dimensionality reduction to - X.- reset()- Reset configuration parameters to their default values. - to_dict()- Return config value in a dict form. - transform([X])- Apply dimensionality reduction to - X.- Attributes Documentation - Uο
- Return the left unitary matrix. - Its shape depends on - full_matrices.
 - VTο
- Return a transpose matrix of the Loadings. - Its shape depends on - full_matrices
 - Xο
- Return the X input dataset (eventually modified by the model). 
 - componentsο
- NDDatasetwith components in feature space (n_components, n_features).- See also - get_components
- Retrieve only the specified number of components. 
 
 - compute_uvο
- Whether or not to compute U and VT in addition to s. 
 - configο
- traitlets.config.Configobject.
 - cumulative_explained_varianceο
- Return Cumulative Explained Variance. 
 - evο
- Return a NDDataset of the explained variance. 
 - ev_cumο
- Return Cumulative Explained Variance. 
 - ev_ratioο
- Return Explained Variance per singular values. 
 - explained_varianceο
- Return a NDDataset of the explained variance. 
 - explained_variance_ratioο
- Return Explained Variance per singular values. 
 - full_matricesο
- If False , U and VT have the shapes (M, k) and (k, N), respectively, where k = min(M, N). Otherwise the shapes will be (M, M) and (N, N), respectively. 
 - logο
- Return - logoutput.
 - n_componentsο
- Number of components that were fitted. 
 - nameο
- Object name 
 - sο
- Return Vector of singular values . 
 - singular_valuesο
- Return a NDDataset containing singular values. 
 - svο
- Return a NDDataset containing singular values. 
 - Methods Documentation - fit(X)[source]ο
- Fit the SVD model on X. - Parameters:
- X ( - NDDatasetor array-like of shape (n_observations, n_features)) β Training data.
- Returns:
- self β The fitted instance itself. 
 - See also - fit_transform
- Fit the model with an input dataset - Xand apply the dimensionality reduction on- X.
- fit_reduce
- Alias of - fit_transform(Deprecated).
 
 - fit_transform(X, Y=None, **kwargs)[source]ο
- Fit the model with - Xand apply the dimensionality reduction on- X.- Parameters:
- X ( - NDDatasetor array-like of shape (n_observations, n_features)) β Training data.
- Y (any) β Depends on the model. 
- **kwargs (keyword parameters, optional) β See Other Parameters. 
 
- Returns:
- NDDatasetβ Dataset with shape (n_observations, n_components).
- Other Parameters:
- n_components ( - int, optional) β The number of components to use for the reduction. If not given the number of components is eventually the one specified or determined in the- fitprocess.
 
 - get_components(n_components=None)ο
- Return the componentβs dataset: (selected n_components, n_features). - Parameters:
- n_components ( - int, optional, default:- None) β The number of components to keep in the output dataset. If- None, all calculated components are returned.
- Returns:
- NDDatasetβ Dataset with shape (n_components, n_features)
 
 - inverse_transform(X_transform=None, **kwargs)ο
- Transform data back to its original space. - In other words, return an input - X_originalwhose reduce/transform would be- X_transform.- Parameters:
- X_transform (array-like of shape (n_observations, n_components), optional) β Reduced - Xdata, where- n_observationsis the number of observations and- n_componentsis the number of components. If- X_transformis not provided, a transform of- Xprovided in- fitis performed first.
- **kwargs (keyword parameters, optional) β See Other Parameters. 
 
- Returns:
- NDDatasetβ Dataset with shape (n_observations, n_features).
- Other Parameters:
- n_components ( - int, optional) β The number of components to use for the reduction. If not given the number of components is eventually the one specified or determined in the- fitprocess.
 - See also - reconstruct
- Alias of inverse_transform (Deprecated). 
 
 - parameters(replace="params", removed="0.8.0") def parameters(self, default=False)[source]ο
- Alias for - paramsmethod.- Deprecated since version 0.8.0: Use - paramsinstead.
 - plotmerit(X=None, X_hat=None, **kwargs)[source]ο
- Plot the input ( - X), reconstructed (- X_hat) and residuals.- \(X\) and \(\hat{X}\) can be passed as arguments. If not, the - Xattribute is used for \(X`and :math:\)hat{X}`is computed by the- inverse_transformmethod- Parameters:
- X ( - NDDataset, optional) β Original dataset. If is not provided (default), the- Xattribute is used and X_hat is computed using- inverse_transform.
- X_hat ( - NDDataset, optional) β Inverse transformed dataset. if- Xis provided,- X_hatmust also be provided as compuyed externally.
- **kwargs (keyword parameters, optional) β See Other Parameters. 
 
- Returns:
- Axesβ Matplotlib subplot axe.
- Other Parameters:
- colors ( - tupleor- ndarrayof 3 colors, optional) β Colors for- X,- X_hatand residuals- E. in the case of 2D, The default colormap is used for- X. By default, the three colors are- NBlue,- NGreenand- NRed(which are colorblind friendly).
- offset ( - float, optional, default:- None) β Specify the separation (in percent) between the \(X\) , \(X_hat\) and \(E\).
- nb_traces ( - intor- 'all', optional) β Number of lines to display. Default is- 'all'.
- **others (Other keywords parameters) β Parameters passed to the internal - plotmethod of the- Xdataset.
 
 
 - reconstruct(X_transform=None, **kwargs)[source]ο
- Transform data back to its original space. - In other words, return an input - X_originalwhose reduce/transform would be- X_transform.- Parameters:
- X_transform (array-like of shape (n_observations, n_components), optional) β Reduced - Xdata, where- n_observationsis the number of observations and- n_componentsis the number of components. If- X_transformis not provided, a transform of- Xprovided in- fitis performed first.
- **kwargs (keyword parameters, optional) β See Other Parameters. 
 
- Returns:
- NDDatasetβ Dataset with shape (n_observations, n_features).
- Other Parameters:
- n_components ( - int, optional) β The number of components to use for the reduction. If not given the number of components is eventually the one specified or determined in the- fitprocess.
 - See also - reconstruct
- Alias of inverse_transform (Deprecated). 
 - Notes - Deprecated in version 0.6. 
 - reduce(X=None, **kwargs)[source]ο
- Apply dimensionality reduction to - X.- Parameters:
- X ( - NDDatasetor array-like of shape (n_observations, n_features), optional) β New data, where n_observations is the number of observations and n_features is the number of features. if not provided, the input dataset of the- fitmethod will be used.
- **kwargs (keyword parameters, optional) β See Other Parameters. 
 
- Returns:
- NDDatasetβ Dataset with shape (n_observations, n_components).
- Other Parameters:
- n_components ( - int, optional) β The number of components to use for the reduction. If not given the number of components is eventually the one specified or determined in the- fitprocess.
 - Notes - Deprecated in version 0.6. 
 - transform(X=None, **kwargs)ο
- Apply dimensionality reduction to - X.- Parameters:
- X ( - NDDatasetor array-like of shape (n_observations, n_features), optional) β New data, where n_observations is the number of observations and n_features is the number of features. if not provided, the input dataset of the- fitmethod will be used.
- **kwargs (keyword parameters, optional) β See Other Parameters. 
 
- Returns:
- NDDatasetβ Dataset with shape (n_observations, n_components).
- Other Parameters:
- n_components ( - int, optional) β The number of components to use for the reduction. If not given the number of components is eventually the one specified or determined in the- fitprocess.
 
 
Examples using spectrochempy.SVD