Dimension reduction of the fish measurements
In a previous exercise, you saw that 2 was a reasonable choice for the "intrinsic dimension" of the fish measurements. Now use PCA for dimensionality reduction of the fish measurements, retaining only the 2 most important components.
The fish measurements have already been scaled for you, and are available as scaled_samples.
Bu egzersiz
Unsupervised Learning in Python
kursunun bir parçasıdırEgzersiz talimatları
- Import
PCAfromsklearn.decomposition. - Create a PCA instance called
pcawithn_components=2. - Use the
.fit()method ofpcato fit it to the scaled fish measurementsscaled_samples. - Use the
.transform()method ofpcato transform thescaled_samples. Assign the result topca_features.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
# 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)