Data Science with Python Certification Data Science with Python Supervised Learning Models 2 — Questions and Answers
Question 1: Which scikit-learn parameter controls the maximum depth of a decision tree to prevent overfitting?
- n_estimators
- max_depth (Correct answer)
- learning_rate
- min_samples_split
Correct answer: max_depth
max_depth limits how deep the tree grows, reducing overfitting by preventing the model from memorizing training data.
Question 2: In logistic regression, what function maps the linear output to a probability between 0 and 1?
- ReLU
- Softmax
- Sigmoid (Correct answer)
- Tanh
Correct answer: Sigmoid
The sigmoid function squashes any real-valued number into the (0,1) range, making it suitable for binary classification probabilities.
Question 3: A Support Vector Machine with an RBF kernel has a high value of gamma. What effect does this have?
- The model underfits with a very smooth decision boundary
- Each training point influences a wide region
- The model overfits with a complex, tightly fitted boundary (Correct answer)
- Regularization strength increases
Correct answer: The model overfits with a complex, tightly fitted boundary
High gamma means each training point has a small radius of influence, causing the model to fit training data very tightly and potentially overfit.
Question 4: Which evaluation metric is most appropriate when false negatives are more costly than false positives, such as in cancer detection?
- Precision
- Recall (Correct answer)
- Specificity
- F1 Score
Correct answer: Recall
Recall (sensitivity) measures the proportion of actual positives correctly identified, minimizing missed cases (false negatives).
Question 5: In a Random Forest, what technique introduces randomness when building each tree?
- Gradient boosting on residuals
- Bootstrap sampling and random feature subsets (Correct answer)
- Pruning by information gain
- L2 regularization on leaf nodes
Correct answer: Bootstrap sampling and random feature subsets
Random Forest uses bootstrap sampling of data rows and random subsets of features at each split, reducing correlation between trees.
Question 6: What does the C parameter control in a Support Vector Classifier?
- The kernel function bandwidth
- The trade-off between margin width and training misclassification (Correct answer)
- The number of support vectors
- The learning rate during optimization
Correct answer: The trade-off between margin width and training misclassification
A large C penalizes misclassifications heavily (low bias, high variance), while a small C allows more misclassifications for a wider margin.
Question 7: Which sklearn method returns both predicted class labels and their probabilities for a classifier?
- predict()
- decision_function()
- predict_proba() (Correct answer)
- score()
Correct answer: predict_proba()
predict_proba() returns an array of shape (n_samples, n_classes) containing the probability of each class for each sample.
Which scikit-learn parameter controls the maximum depth of a decision tree to prevent overfitting?