April 2018
Beginner to intermediate
282 pages
6h 52m
English
The following code block shows you how to apply PCA with two components and visualize the results:
# PCAfrom sklearn.decomposition import PCApca = PCA(n_components=2, whiten=True)pca = pca.fit_transform(df)plt.scatter(pca[:, 0], pca[:, 1], c=data.target, cmap="RdBu_r", edgecolor="Red", alpha=0.35)plt.colorbar()plt.title('PCA, n_components=2')plt.show()
We get the following plot from the preceding code:

Here, you can see the red class (dark gray) is very condensed into one particular area and it's hard to separate classes. Differences in variances distort our view and scaling ...
Read now
Unlock full access