시작하기무료로 시작하기

물고기 측정값의 차원 축소

이전 연습 문제에서 물고기 측정값의 "내재 차원"으로 2가 합리적인 선택임을 확인했어요. 이제 PCA를 사용해 물고기 측정값의 차원을 축소하고, 가장 중요한 2개의 구성 요소만 유지해 보세요.

물고기 측정값은 이미 스케일링되어 있으며 scaled_samples로 제공됩니다.

이 연습은 강의의 일부입니다

Python으로 배우는 Unsupervised Learning

강의 보기

연습 안내

  • sklearn.decomposition에서 PCA를 가져오세요.
  • n_components=2pca라는 이름의 PCA 인스턴스를 만드세요.
  • pca.fit() 메서드를 사용해 스케일링된 물고기 측정값 scaled_samples에 맞추세요.
  • pca.transform() 메서드로 scaled_samples를 변환하고, 결과를 pca_features에 할당하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# Import PCA
____

# Create a PCA model with 2 components: pca
pca = ____

# Fit the PCA instance to the scaled samples
____

# Transform the scaled samples: pca_features
pca_features = ____

# Print the shape of pca_features
print(pca_features.shape)
코드 편집 및 실행