July 2018
Beginner to intermediate
406 pages
9h 55m
English
Let's consider the following artificial dataset, which is visualized in the following left-hand plot diagram:
>>> x1 = np.arange(0, 10, .2) >>> x2 = x1+np.random.normal(loc=0, scale=1, size=len(x1)) >>> X = np.c_[(x1, x2)] >>> good = (x1>5) | (x2>5) # some arbitrary classes >>> bad = ~good

Scikit-learn provides the PCA class in its decomposition package. In this example, we can clearly see that one dimension should be enough to describe the data. We can specify this using the n_components parameter:
>>> from sklearn import linear_model, decomposition, datasets >>> pca = decomposition.PCA(n_components=1)
Also, here, we can use ...
Read now
Unlock full access