Data Science with Python Certification Data Science with Python Supervised Learning Models 5 — Questions and Answers
Question 1: What is the key difference between Lasso (L1) and Ridge (L2) regularization in linear models?
- Lasso uses squared penalties; Ridge uses absolute value penalties
- Lasso can reduce coefficients to exactly zero, performing feature selection; Ridge shrinks but rarely zeros out (Correct answer)
- Ridge performs feature selection; Lasso only shrinks coefficients
- Both produce identical results but differ in computational cost
Correct answer: Lasso can reduce coefficients to exactly zero, performing feature selection; Ridge shrinks but rarely zeros out
L1 (Lasso) regularization produces sparse solutions by driving some coefficients to exactly zero, effectively selecting features, while L2 shrinks all coefficients smoothly.
Question 2: In K-Nearest Neighbors classification, increasing k generally causes the model to:
- Overfit with a more complex decision boundary
- Underfit with a smoother, less complex decision boundary (Correct answer)
- Train faster on large datasets
- Become more sensitive to outliers
Correct answer: Underfit with a smoother, less complex decision boundary
Larger k averages over more neighbors, smoothing the decision boundary and reducing variance at the cost of potentially higher bias.
Question 3: Which metric should be used for a multi-class classification problem with imbalanced classes?
- Accuracy
- Macro-averaged F1 Score (Correct answer)
- Mean Absolute Error
- R-squared
Correct answer: Macro-averaged F1 Score
Macro-averaged F1 computes F1 per class independently and averages them, giving equal weight to each class regardless of support.
Question 4: What is the purpose of the learning_rate parameter in Gradient Boosting?
- Controls the number of trees in the ensemble
- Shrinks the contribution of each tree to prevent overfitting (Correct answer)
- Sets the depth of individual trees
- Determines the fraction of samples used for each tree
Correct answer: Shrinks the contribution of each tree to prevent overfitting
A smaller learning_rate means each tree contributes less, requiring more trees but often yielding better generalization.
Question 5: When would you use sklearn's PolynomialFeatures transformer before fitting a linear regression model?
- When the relationship between features and target is nonlinear (Correct answer)
- When you want to reduce the number of input features
- When features have very different scales
- When the target variable is categorical
Correct answer: When the relationship between features and target is nonlinear
PolynomialFeatures creates interaction and polynomial terms, allowing a linear model to capture nonlinear relationships in the data.
Question 6: In an sklearn classification report, what does 'support' represent for each class?
- The number of support vectors for that class
- The number of actual instances of that class in the test set (Correct answer)
- The model's confidence score for that class
- The number of features used to classify that class
Correct answer: The number of actual instances of that class in the test set
Support is the count of true occurrences of each class in the test labels, reflecting the class distribution of the evaluation set.
Question 7: Which of the following best describes the bias-variance tradeoff in supervised learning?
- High bias models overfit; high variance models underfit
- High bias models underfit with systematic error; high variance models overfit by being too sensitive to training data (Correct answer)
- Bias and variance always increase together as model complexity grows
- Reducing variance always reduces bias simultaneously
Correct answer: High bias models underfit with systematic error; high variance models overfit by being too sensitive to training data
High bias indicates the model makes strong simplifying assumptions (underfitting), while high variance means it captures noise in training data (overfitting).
What is the key difference between Lasso (L1) and Ridge (L2) regularization in linear models?