Kernel-PCA
目次
Kernel-PCA¶
import numpy as np
import matplotlib.pyplot as plt
import japanize_matplotlib
from sklearn.datasets import make_circles
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Input In [1], in <cell line: 2>()
1 import numpy as np
----> 2 import matplotlib.pyplot as plt
3 import japanize_matplotlib
4 from sklearn.datasets import make_circles
ModuleNotFoundError: No module named 'matplotlib'
# 表示する文字サイズを調整
plt.rc("font", size=20)
plt.rc("legend", fontsize=16)
plt.rc("xtick", labelsize=14)
plt.rc("ytick", labelsize=14)
# youtube動画を表示
import IPython.display
# IPython.display.YouTubeVideo("XXX", width="500px")
実験用のデータ¶
X, y = make_circles(n_samples=400, factor=0.3, noise=0.15)
fig = plt.figure(figsize=(8, 8))
plt.scatter(X[:, 0], X[:, 1], c=y)
<matplotlib.collections.PathCollection at 0x7fc8e1c9bbe0>
KernelPCA¶
from sklearn.decomposition import KernelPCA
kpca = KernelPCA(kernel="rbf", degree=2, gamma=3)
X_kpca = kpca.fit_transform(X)
fig = plt.figure(figsize=(8, 8))
plt.scatter(X_kpca[:, 0], X_kpca[:, 1], c=y)
<matplotlib.collections.PathCollection at 0x7fc8e28323a0>