次元削減:可視化手法

Pythonで学ぶMachine Learning面接対策

Lisa Stuart

Data Scientist

なぜ次元削減か?

  1. 学習の高速化
  2. 可視化
  3. 精度向上
Pythonで学ぶMachine Learning面接対策

可視化手法

  • PCA
  • t-SNE
Pythonで学ぶMachine Learning面接対策

PCA による可視化

PCA プロット

1 https://districtdatalabs.silvrback.com/principal-component-analysis-with-python
Pythonで学ぶMachine Learning面接対策

スクリープロット

スクリープロット

1 https://towardsdatascience.com/a-step-by-step-explanation-of-principal-component-analysis-b836fb9c97e2
Pythonで学ぶMachine Learning面接対策

t-SNE

  • 確率的
  • データ点のペア
  • 低次元埋め込み
  • 埋め込みをプロット
Pythonで学ぶMachine Learning面接対策

t-SNE による可視化

# t-sne with loan data
from sklearn.manifold import TSNE
import seaborn as sns

loans =  pd.read_csv('loans_dataset.csv')

# Feature matrix
X = loans.drop('Loan Status', axis=1)

tsne = TSNE(n_components=2, verbose=1, perplexity=40)
tsne_results = tsne.fit_transform(X)

loans['t-SNE-PC-one'] = tsne_results[:,0]
loans['t-SNE-PC-two'] = tsne_results[:,1]

# t-sne viz
plt.figure(figsize=(16,10))
sns.scatterplot(
    x="t-SNE-PC-one", y="t-SNE-PC-two",
    hue="Loan Status",
    palette=sns.color_palette(["grey","blue"]),
    data=loans,
    legend="full",
    alpha=0.3
)
1 https://scikit-learn.org/stable/modules/generated/sklearn.manifold.TSNE.html
Pythonで学ぶMachine Learning面接対策

t-SNE による可視化

t-sne プロット

Pythonで学ぶMachine Learning面接対策

PCA と t-SNE の比較(Digits)

手書き数字の PCA と t-SNE

1 https://towardsdatascience.com/visualising-high-dimensional-datasets-using-pca-and-t-sne-in-python-8ef87e7915b
Pythonで学ぶMachine Learning面接対策

練習してみましょう!

Pythonで学ぶMachine Learning面接対策

Preparing Video For Download...