주성분 선택

Python으로 배우는 차원 축소

Jeroen Boeye

Head of Machine Learning, Faktion

설명 분산 임계값 설정

pipe = Pipeline([
        ('scaler', StandardScaler()),
        ('reducer', PCA(n_components=0.9))])

# Fit the pipe to the data pipe.fit(poke_df) print(len(pipe['reducer'].components_))
5
Python으로 배우는 차원 축소

최적의 컴포넌트 수

pipe.fit(poke_df)

var = pipe['reducer'].explained_variance_ratio_

plt.plot(var)

plt.xlabel('Principal component index')
plt.ylabel('Explained variance ratio')
plt.show()

설명 분산 비율

Python으로 배우는 차원 축소

최적의 컴포넌트 수

pipe.fit(poke_df)

var = pipe['reducer'].explained_variance_ratio_

plt.plot(var)

plt.xlabel('Principal component index')
plt.ylabel('Explained variance ratio')
plt.show()

설명 분산 비율 엘보

Python으로 배우는 차원 축소

PCA 작업

PCA 적합-변환 도식 1

Python으로 배우는 차원 축소

PCA 작업

PCA 적합-변환 도식 2

Python으로 배우는 차원 축소

PCA 작업

PCA 적합-변환 도식 3

Python으로 배우는 차원 축소

이미지 압축

원본 얼굴

Python으로 배우는 차원 축소

이미지 압축

print(X_test.shape)
(15, 2914)

62 x 47 픽셀 = 2914 그레이스케일 값

print(X_train.shape)
(1333, 2914)
Python으로 배우는 차원 축소

이미지 압축

pipe = Pipeline([
        ('scaler', StandardScaler()),
        ('reducer', PCA(n_components=290))])

pipe.fit(X_train)
pc = pipe.fit_transform(X_test) print(pc.shape)
(15, 290)
Python으로 배우는 차원 축소

이미지 재구성

pc = pipe.transform(X_test)

print(pc.shape)
(15, 290)
X_rebuilt = pipe.inverse_transform(pc)

print(X_rebuilt.shape)
(15, 2914)
img_plotter(X_rebuilt)

압축된 얼굴

Python으로 배우는 차원 축소

이미지 재구성

원본 얼굴

압축된 얼굴

Python으로 배우는 차원 축소

연습해 봅시다!

Python으로 배우는 차원 축소

Preparing Video For Download...