Scikit-learn's PCA

As usual, scikit-learn saves the day by implementing this procedure in an easy to use transformer so that we don't have to go through that manual process each time we wish to use this powerful process:

  1. We can import it from scikit-learn's decomposition module:
# scikit-learn's version of PCAfrom sklearn.decomposition import PCA
  1. To mimic the process we performed with the iris dataset, let's instantiate a PCA object with only two components:
# Like any other sklearn module, we first instantiate the classpca = PCA(n_components=2)
  1. Now, we can fit our PCA to the data:
# fit the PCA to our datapca.fit(iris_X)
  1. Let's take a look at some of the attributes of the PCA object to see if they match up with what we achieved in ...

Get Feature Engineering Made Easy now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.