In this section, we will perform kernel PCA to find eigenvectors and eigenvalues so that we can reconstruct the Dow index.
Applying a kernel PCA
Finding eigenvectors and eigenvalues
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...