KernelPca.m is a MATLAB class file that enables you to do the following three things with a very short code.
- fitting a kernel pca model with training data with three kernel functions(gaussian, polynomial, linear) (demo.m)
- projection of new data with the fitted pca model (demo.m)
- confirming the contribution ratio (demo2.m)
↓
kpca = KernelPca(X, 'gaussian', 'gamma', 2.5, 'AutoScale', true);
projected_X = project(kpca, X, 2);
projected_Xtest = project(kpca, Xtest, 2);↓
load fisheriris
linear_kpca = KernelPca(meas, 'linear');↓
plot([1 2 3 4], linear_kpca.contribution_ratio(1:4));- Kernel pca with three types of kernel function: linear[^1], gaussian, and polynomial.
- Optional pre-processing.
- New data projection without re-training the model.
Making a kernel pca model (an instance of
KernelPcaclass) usingtrain_data
train_datarow vector dataset (size:N-by-D, where N is the number of vectors and D is the dimention of the vectors).
kerneltype of the kernel function specified as char. ('linear', 'gaussian', or 'polynomial').
gammahyper parameter of gaussian kernel. default:2
rhyper parameter of polynomial kernel. default:1
dhyper parameter of polynomial kernel. default:2
AutoScaleflag for auto scaling. If this is true, each variable is scaled using its standard deviation. default:false
kpcatrained kernel pca model as a KernelPca class. New data can be projected by this.
Projecting the data to subspace by using kpca that is a fitted kernel pca model.
kpcatrained kernel pca model as a KernelPca class.
datarow vector dataset.
dimsubspace dimention number of the projected data (dim<D, where D is the original dimention number of input data)
projected_dataprojected row vector dataset.
Setting a fitted instance compact by releasing some properties not used for projection.
kpcatrained kernel pca model as a KernelPca class.
MaxDimmax number of the subspace dimention specified as an integer. If you specify this, unnecessary part of the coefficient is released.
[^1]: Note that linear kernel is corresponding to the normal pca, but the internal algorithm is different from it.
[^2]: Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.
This code was written in the environment of MATLAB R2017a - academic use
Masaki Kitayama


