April 2019
Intermediate to advanced
426 pages
11h 13m
English
We can perform a kernel PCA using the KernelPCA class of the sklearn.decomposition module in Python. The default kernel method is linear. The dataset that's used in PCA is required to be normalized, which we can perform with z-scoring. The following code do this:
In [ ]: from sklearn.decomposition import KernelPCA fn_z_score = lambda x: (x - x.mean()) / x.std() df_z_components = daily_df_components.apply(fn_z_score) fitted_pca = KernelPCA().fit(df_z_components)
The fn_z_score variable is an inline function to perform z-scoring on a pandas DataFrame, which is applied with the apply() method. These normalized datasets can be fitted into a kernel PCA with the fit() method. The fitted results of the ...
Read now
Unlock full access