Bird
Raised Fist0
ML Pythonml~20 mins

Dimensionality reduction visualization in ML Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Dimensionality Reduction Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Purpose of Dimensionality Reduction Visualization
Why do we use dimensionality reduction techniques like t-SNE or PCA for visualization in machine learning?
ATo reduce the number of features so the model trains faster without losing any information
BTo increase the number of features for better model accuracy
CTo transform high-dimensional data into 2D or 3D so humans can visually understand patterns
DTo remove noisy data points from the dataset automatically
Attempts:
2 left
💡 Hint
Think about how humans can best understand complex data.
❓ Predict Output
intermediate
2:00remaining
Output of PCA Dimensionality Reduction Code
What is the shape of the transformed data after applying PCA with 2 components on a dataset with shape (100, 5)?
ML Python
from sklearn.decomposition import PCA
import numpy as np
X = np.random.rand(100, 5)
pca = PCA(n_components=2)
X_pca = pca.fit_transform(X)
print(X_pca.shape)
A(100, 2)
B(2, 100)
C(5, 2)
D(100, 5)
Attempts:
2 left
💡 Hint
PCA reduces features but keeps the number of samples the same.
❓ Model Choice
advanced
2:00remaining
Choosing a Dimensionality Reduction Method for Visualization
You have a dataset with 1000 features and want to visualize clusters in 2D. Which method is best for preserving local structure and showing clusters clearly?
APCA because it preserves global variance and is fast
BLinear Regression because it reduces features by fitting a line
CK-Means clustering because it reduces dimensions by grouping data
Dt-SNE because it preserves local neighbor distances and reveals clusters well
Attempts:
2 left
💡 Hint
Think about which method is designed to show clusters clearly in low dimensions.
❓ Metrics
advanced
2:00remaining
Interpreting Explained Variance Ratio in PCA
After applying PCA with 3 components, the explained variance ratios are [0.5, 0.3, 0.1]. What does this tell you about the data?
AThe components explain 50%, 30%, and 10% of the samples respectively
BThe first component explains 50% of the variance, the second 30%, and the third 10%, totaling 90% variance explained
CThe PCA model is overfitting because variance ratios should sum to 1
DThe data has 3 features only because PCA returned 3 components
Attempts:
2 left
💡 Hint
Explained variance ratio shows how much information each component keeps.
🔧 Debug
expert
3:00remaining
Debugging t-SNE Visualization Code
You run this code to visualize data with t-SNE but get a ValueError: 'perplexity must be less than n_samples'. What is the cause?
ML Python
from sklearn.manifold import TSNE
import numpy as np
X = np.random.rand(10, 50)
tsne = TSNE(n_components=2, perplexity=30)
X_embedded = tsne.fit_transform(X)
print(X_embedded.shape)
AThe perplexity value 30 is too high for only 10 samples; it must be less than the number of samples
BThe number of components must be equal to the number of features
CThe input data X must be 2D but here it is 3D
DTSNE requires the input data to be normalized between 0 and 1
Attempts:
2 left
💡 Hint
Check the relationship between perplexity and sample size in t-SNE.

Practice

(1/5)
1. What is the main purpose of dimensionality reduction in data visualization?
easy
A. To simplify complex data into fewer dimensions for easier understanding
B. To increase the number of features in the dataset
C. To remove all data points that are outliers
D. To convert numerical data into text format

Solution

  1. Step 1: Understand dimensionality reduction goal

    Dimensionality reduction aims to reduce many features into fewer ones while keeping important information.
  2. Step 2: Connect to visualization purpose

    Reducing dimensions helps us visualize data in 2D or 3D, making it easier to see patterns.
  3. Final Answer:

    To simplify complex data into fewer dimensions for easier understanding -> Option A
  4. Quick Check:

    Dimensionality reduction = simplify data [OK]
Hint: Dimensionality reduction means fewer features to see data clearly [OK]
Common Mistakes:
  • Thinking it increases features instead of reducing
  • Confusing it with data cleaning or outlier removal
  • Believing it changes data type to text
2. Which of the following is the correct way to import PCA from scikit-learn in Python?
easy
A. import PCA from sklearn.decomposition
B. from sklearn.decomposition import PCA
C. from sklearn import PCA
D. import decomposition.PCA from sklearn

Solution

  1. Step 1: Recall correct Python import syntax

    Python imports use 'from module import class' format for specific classes.
  2. Step 2: Match with scikit-learn PCA import

    PCA is in sklearn.decomposition, so correct import is 'from sklearn.decomposition import PCA'.
  3. Final Answer:

    from sklearn.decomposition import PCA -> Option B
  4. Quick Check:

    Correct import syntax = from sklearn.decomposition import PCA [OK]
Hint: Use 'from module import class' for specific imports [OK]
Common Mistakes:
  • Using wrong import order or syntax
  • Trying to import PCA directly from sklearn
  • Using 'import' with 'from' incorrectly
3. Given this Python code using PCA, what will be the shape of X_pca?
from sklearn.decomposition import PCA
import numpy as np
X = np.random.rand(100, 10)
pca = PCA(n_components=2)
X_pca = pca.fit_transform(X)
medium
A. (100, 2)
B. (2, 10)
C. (100, 10)
D. (10, 2)

Solution

  1. Step 1: Understand input data shape

    X has 100 samples and 10 features, so shape is (100, 10).
  2. Step 2: Apply PCA with n_components=2

    PCA reduces features from 10 to 2, keeping sample count same, so output shape is (100, 2).
  3. Final Answer:

    (100, 2) -> Option A
  4. Quick Check:

    Samples stay same, features reduced = (100, 2) [OK]
Hint: Output shape = (samples, n_components) after PCA [OK]
Common Mistakes:
  • Confusing samples and features dimensions
  • Thinking PCA changes number of samples
  • Mixing up rows and columns in shape
4. This code tries to visualize data with t-SNE but throws an error. What is the likely cause?
from sklearn.manifold import TSNE
import numpy as np
X = np.random.rand(50, 5)
tsne = TSNE(n_components=3)
X_embedded = tsne.fit_transform(X)
medium
A. t-SNE does not support n_components greater than 2
B. t-SNE requires integer input data
C. Input data must have at least 10 features
D. t-SNE supports n_components=3, so no error here

Solution

  1. Step 1: Check t-SNE n_components support

    t-SNE supports 2 or 3 components for visualization, so n_components=3 is valid.
  2. Step 2: Verify input data and types

    Input X is float data with shape (50, 5), which is acceptable for t-SNE.
  3. Final Answer:

    t-SNE supports n_components=3, so no error here -> Option D
  4. Quick Check:

    t-SNE allows 3D output [OK]
Hint: t-SNE supports 2D or 3D outputs [OK]
Common Mistakes:
  • Assuming t-SNE only supports 2D
  • Thinking input must have many features
  • Believing t-SNE needs integer data
5. You have a dataset with 1000 features and want to visualize clusters clearly. Which approach is best?
hard
A. Use PCA with 2 components because it is fast but may miss clusters
B. Use raw data without reduction for best cluster visualization
C. Use t-SNE with 2 components because it shows clusters well despite being slower
D. Use PCA with 100 components to keep most information

Solution

  1. Step 1: Consider dataset size and visualization goal

    With 1000 features, dimensionality reduction is needed to visualize clusters clearly.
  2. Step 2: Compare PCA and t-SNE for cluster visualization

    PCA is fast but focuses on variance, may miss clusters. t-SNE is slower but better at showing clusters in 2D.
  3. Step 3: Choose best method for clear cluster visualization

    t-SNE with 2 components is best to reveal clusters clearly despite slower speed.
  4. Final Answer:

    Use t-SNE with 2 components because it shows clusters well despite being slower -> Option C
  5. Quick Check:

    t-SNE = better cluster visualization [OK]
Hint: t-SNE reveals clusters better than PCA in 2D [OK]
Common Mistakes:
  • Choosing PCA for cluster clarity over t-SNE
  • Using too many PCA components for visualization
  • Trying to visualize raw high-dimensional data directly
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard