Let's see how we can perform a kernel PCA:
- Create a new Python file and import the following packages (the full code is given in the kpca.py file that is provided for you):
import numpy as np import matplotlib.pyplot as plt from sklearn.decomposition import PCA, KernelPCA from sklearn.datasets import make_circles
- Define the seed value for the random number generator. This is needed to generate data samples for analysis:
# Set the seed for random number generator np.random.seed(7)
- Generate data that is distributed in concentric circles to demonstrate how PCA doesn't work in this case:
# Generate samples X, y = make_circles(n_samples=500, factor=0.2, noise=0.04)
- Perform PCA on this data:
# Perform PCA pca = PCA() ...