1. Learn
  2. /
  3. Courses
  4. /
  5. Preprocessing for Machine Learning in Python

Connected

Exercise

Using PCA

In this exercise, you'll apply PCA to the wine dataset, to see if you can increase the model's accuracy.

Instructions

100 XP
  • Instantiate a PCA object.
  • Define the features (X) and labels (y) from wine, using the labels in the "Type" column.
  • Apply PCA to X_train and X_test, ensuring no data leakage, and store the transformed values as pca_X_train and pca_X_test.
  • Print out the .explained_variance_ratio_ attribute of pca to check how much variance is explained by each component.