Chapter 8: Dimensionality Reduction Flashcards

1
Q

What are the main motivations for reducing a dataset’s dimensionality? What are the main drawbacks?

A

The main motivations for dimensionality reduction are:
-To speed up a subsequent training algorithm (in some cases it may even remove noise and redundant features, making the training algorithm perform better)
-To visualize the data and gain insights on the most important features
-To save space (compression)

The main drawbacks are:
-Some information is lost, possibly degrading the performance of subsequent training algorithms.
-It can be computationally intensive.
-It adds some complexity to your Machine Learning pipelines.
-Transformed features are often hard to interpret.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the curse of dimensionality?

A

The curse of dimensionality refers to the fact that many problems that do not exist in low-dimensional space arise in high-dimensional space. In Machine Learning, one common manifestation is the fact that randomly sampled high-dimensional vectors are generally far from one another, increasing the risk of overfitting and making it very difficult to identify patterns without having plenty of training data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Once a dataset’s dimensionality has been reduced, is it possible to reverse the operation? If so, how? If not, why?

A

Once a dataset’s dimensionality has been reduced using one of the algorithms we discussed, it is almost always impossible to perfectly reverse the operation, because some information gets lost during dimensionality reduction. Moreover, while some algorithms (such as PCA) have a simple reverse transformation procedure that can reconstruct a dataset relatively similar to the original, other algorithms (such as t-SNE) do not.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Can PCA be used to reduce the dimensionality of a highly nonlinear dataset?

A

PCA can be used to significantly reduce the dimensionality of most datasets, even if they are highly nonlinear, because it can at least get rid of useless dimensions. However, if there are no useless dimensions—as in the Swiss roll dataset—then reducing dimensionality with PCA will lose too much information. You want to unroll the Swiss roll, not squash it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Suppose you perform PCA on a 1,000-dimensional dataset, setting the explained variance ratio to 95%. How many dimensions will the resulting dataset have?

A

That’s a trick question: it depends on the dataset. Let’s look at two extreme examples. First, suppose the dataset is composed of points that are almost perfectly aligned. In this case, PCA can reduce the dataset down to just one dimension while still preserving 95% of the variance. Now imagine that the dataset is composed of perfectly random points, scattered all around the 1,000 dimensions. In this case roughly 950 dimensions are required to preserve 95% of the variance. So the answer is, it depends on the dataset, and it could be any number between 1 and 950. Plotting the explained variance as a function of the number of dimensions is one way to get a rough idea of the dataset’s intrinsic dimensionality.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In what cases would you use regular PCA, incremental PCA, randomized PCA, or random projection?

A

Regular PCA is the default, but it works only if the dataset fits in memory. Incremental PCA is useful for large datasets that don’t fit in memory, but it is slower than regular PCA, so if the dataset fits in memory you should prefer regular PCA. Incremental PCA is also useful for online tasks, when you need to apply PCA on the fly, every time a new instance arrives. Randomized PCA is useful when you want to considerably reduce dimensionality and the dataset fits in memory; in this case, it is much faster than regular PCA. Finally, Random Projection is great for very high-dimensional datasets.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How can you evaluate the performance of a dimensionality reduction algorithm on your dataset?

A

Intuitively, a dimensionality reduction algorithm performs well if it eliminates a lot of dimensions from the dataset without losing too much information. One way to measure this is to apply the reverse transformation and measure the reconstruction error. However, not all dimensionality reduction algorithms provide a reverse transformation. Alternatively, if you are using dimensionality reduction as a preprocessing step before another Machine Learning algorithm (e.g., a Random Forest classifier), then you can simply measure the performance of that second algorithm; if dimensionality reduction did not lose too much information, then the algorithm should perform just as well as when using the original dataset.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Does it make any sense to chain two different dimensionality reduction algorithms?

A

It can absolutely make sense to chain two different dimensionality reduction algorithms. A common example is using PCA or Random Projection to quickly get rid of a large number of useless dimensions, then applying another much slower dimensionality reduction algorithm, such as LLE. This two-step approach will likely yield roughly the same performance as using LLE only, but in a fraction of the time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Load the MNIST dataset (introduced in Chapter 3) and split it into a training set and a test set (take the first 60,000 instances for training, and the remaining 10,000 for testing). Train a random forest classifier on the dataset and time how long it takes, then evaluate the resulting model on the test set. Next, use PCA to reduce the dataset’s dimensionality, with an explained variance ratio of 95%. Train a new random forest classifier on the reduced dataset and see how long it takes. Was training much faster? Next, evaluate the classifier on the test set. How does it compare to the previous classifier? Try again with an SGDClassifier. How much does PCA help now?

A

https://colab.research.google.com/github/ageron/handson-ml3/blob/main/08_dimensionality_reduction.ipynb#scrollTo=49iyOQAF3H4X

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Use t-SNE to reduce the first 5,000 images of the MNIST dataset down to 2 dimensions and plot the result using Matplotlib. You can use a scatterplot using 10 different colors to represent each image’s target class. Alternatively, you can replace each dot in the scatterplot with the corresponding instance’s class (a digit from 0 to 9), or even plot scaled-down versions of the digit images themselves (if you plot all digits the visualization will be too cluttered, so you should either draw a random sample or plot an instance only if no other instance has already been plotted at a close distance). You should get a nice visualization with well-separated clusters of digits. Try using other dimensionality reduction algorithms, such as PCA, LLE, or MDS, and compare the resulting visualizations.

A

https://colab.research.google.com/github/ageron/handson-ml3/blob/main/08_dimensionality_reduction.ipynb#scrollTo=49iyOQAF3H4X

How well did you know this?
1
Not at all
2
3
4
5
Perfectly