KernelPCA
¶
-
class
ibex.sklearn.decomposition.
KernelPCA
(n_components=None, kernel='linear', gamma=None, degree=3, coef0=1, kernel_params=None, alpha=1.0, fit_inverse_transform=False, eigen_solver='auto', tol=0, max_iter=None, remove_zero_eig=False, random_state=None, copy_X=True, n_jobs=1)¶ Bases:
sklearn.decomposition.kernel_pca.KernelPCA
,ibex._base.FrameMixin
Note
The documentation following is of the class wrapped by this class. There are some changes, in particular:
- A parameter
X
denotes apandas.DataFrame
. - A parameter
y
denotes apandas.Series
.
Note
The documentation following is of the original class wrapped by this class. This class wraps the attribute
components_
.Example:
>>> import pandas as pd >>> import numpy as np >>> from ibex.sklearn import datasets >>> from ibex.sklearn.decomposition import PCA as PdPCA
>>> iris = datasets.load_iris() >>> features = iris['feature_names'] >>> iris = pd.DataFrame( ... np.c_[iris['data'], iris['target']], ... columns=features+['class'])
>>> iris[features] sepal length (cm) sepal width (cm) petal length (cm) petal width (cm) 0 5.1 3.5 1.4 0.2 1 4.9 3.0 1.4 0.2 2 4.7 3.2 1.3 0.2 3 4.6 3.1 1.5 0.2 4 5.0 3.6 1.4 0.2 ...
>>> PdPCA(n_components=2).fit(iris[features], iris['class']).transform(iris[features]) comp_0 comp_1 0 -2.684207 ...0.326607 1 -2.715391 ...0.169557 2 -2.889820 ...0.137346 3 -2.746437 ...0.311124 4 -2.728593 ...0.333925 ...
Kernel Principal component analysis (KPCA)
Non-linear dimensionality reduction through the use of kernels (see Pairwise metrics, Affinities and Kernels).
Read more in the User Guide.
- n_components : int, default=None
- Number of components. If None, all non-zero components are kept.
- kernel : “linear” | “poly” | “rbf” | “sigmoid” | “cosine” | “precomputed”
- Kernel. Default=”linear”.
- gamma : float, default=1/n_features
- Kernel coefficient for rbf, poly and sigmoid kernels. Ignored by other kernels.
- degree : int, default=3
- Degree for poly kernels. Ignored by other kernels.
- coef0 : float, default=1
- Independent term in poly and sigmoid kernels. Ignored by other kernels.
- kernel_params : mapping of string to any, default=None
- Parameters (keyword arguments) and values for kernel passed as callable object. Ignored by other kernels.
- alpha : int, default=1.0
- Hyperparameter of the ridge regression that learns the inverse transform (when fit_inverse_transform=True).
- fit_inverse_transform : bool, default=False
- Learn the inverse transform for non-precomputed kernels. (i.e. learn to find the pre-image of a point)
- eigen_solver : string [‘auto’|’dense’|’arpack’], default=’auto’
- Select eigensolver to use. If n_components is much less than the number of training samples, arpack may be more efficient than the dense eigensolver.
- tol : float, default=0
- Convergence tolerance for arpack. If 0, optimal value will be chosen by arpack.
- max_iter : int, default=None
- Maximum number of iterations for arpack. If None, optimal value will be chosen by arpack.
- remove_zero_eig : boolean, default=False
- If True, then all components with zero eigenvalues are removed, so that the number of components in the output may be < n_components (and sometimes even zero due to numerical instability). When n_components is None, this parameter is ignored and components with zero eigenvalues are removed regardless.
- random_state : int, RandomState instance or None, optional (default=None)
If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random. Used when
eigen_solver
== ‘arpack’.New in version 0.18.
- copy_X : boolean, default=True
If True, input X is copied and stored by the model in the X_fit_ attribute. If no further changes will be done to X, setting copy_X=False saves memory by storing a reference.
New in version 0.18.
- n_jobs : int, default=1
The number of parallel jobs to run. If -1, then the number of jobs is set to the number of CPU cores.
New in version 0.18.
- lambdas_ : array, (n_components,)
- Eigenvalues of the centered kernel matrix in decreasing order. If n_components and remove_zero_eig are not set, then all values are stored.
- alphas_ : array, (n_samples, n_components)
- Eigenvectors of the centered kernel matrix. If n_components and remove_zero_eig are not set, then all components are stored.
- dual_coef_ : array, (n_samples, n_features)
- Inverse transform matrix. Set if fit_inverse_transform is True.
- X_transformed_fit_ : array, (n_samples, n_components)
- Projection of the fitted data on the kernel principal components.
- X_fit_ : (n_samples, n_features)
- The data used to fit the model. If copy_X=False, then X_fit_ is a reference. This attribute is used for the calls to transform.
- Kernel PCA was introduced in:
- Bernhard Schoelkopf, Alexander J. Smola, and Klaus-Robert Mueller. 1999. Kernel principal component analysis. In Advances in kernel methods, MIT Press, Cambridge, MA, USA 327-352.
-
fit
(X, y=None)[source]¶ Note
The documentation following is of the class wrapped by this class. There are some changes, in particular:
- A parameter
X
denotes apandas.DataFrame
. - A parameter
y
denotes apandas.Series
.
Fit the model from data in X.
- X : array-like, shape (n_samples, n_features)
- Training vector, where n_samples in the number of samples and n_features is the number of features.
- self : object
- Returns the instance itself.
- A parameter
-
fit_transform
(X, y=None, **params)[source]¶ Note
The documentation following is of the class wrapped by this class. There are some changes, in particular:
- A parameter
X
denotes apandas.DataFrame
. - A parameter
y
denotes apandas.Series
.
Fit the model from data in X and transform X.
- X : array-like, shape (n_samples, n_features)
- Training vector, where n_samples in the number of samples and n_features is the number of features.
X_new : array-like, shape (n_samples, n_components)
- A parameter
-
inverse_transform
(X)[source]¶ Note
The documentation following is of the class wrapped by this class. There are some changes, in particular:
- A parameter
X
denotes apandas.DataFrame
. - A parameter
y
denotes apandas.Series
.
Transform X back to original space.
X : array-like, shape (n_samples, n_components)
X_new : array-like, shape (n_samples, n_features)
“Learning to Find Pre-Images”, G BakIr et al, 2004.
- A parameter
-
transform
(X)[source]¶ Note
The documentation following is of the class wrapped by this class. There are some changes, in particular:
- A parameter
X
denotes apandas.DataFrame
. - A parameter
y
denotes apandas.Series
.
Transform X.
X : array-like, shape (n_samples, n_features)
X_new : array-like, shape (n_samples, n_components)
- A parameter
- A parameter