text_plain_output_1.png image_output_1.png
from sklearn.datasets import load_iris

from sklearn.decomposition import PCA

import numpy as np

iris = load_iris()
X = iris['data']
y = iris['target']
pca = PCA(n_components=2)
X_pca = pca.fit_transform(X)
X_scaled = X_pca
ax = plt.axes()
cor = ['blue', 'red', 'green']
for i in range(3):
    idx = np.where(y == i)
    ax.scatter(X_scaled[idx, 0], X_scaled[idx, 1], color=cor[i], alpha=0.5, zorder=2)
ax.set_aspect('equal')
ax.grid(visible=True, zorder=1)
ax.set(title='Ground-truth')