Data Science with Python Certification Data Science with Python (Basic) 5 — Questions and Answers
Question 1: In a list comprehension [x**2 for x in range(5) if x % 2 == 0], how many elements does the result contain?
- 5
- 3 (Correct answer)
- 2
- 4
Correct answer: 3
range(5) produces 0,1,2,3,4; filtering by x%2==0 keeps 0,2,4 — three values — so the result has 3 elements: [0,4,16].
Question 2: Which measure of central tendency is most robust to outliers?
- Mean
- Mode
- Median (Correct answer)
- Standard deviation
Correct answer: Median
The median (middle value) is resistant to outliers because it depends on rank order, not the actual extreme values.
Question 3: What does np.where(condition, x, y) return?
- The index where condition is True
- An array with x where condition is True and y where it is False (Correct answer)
- A boolean mask of condition
- The count of True values in condition
Correct answer: An array with x where condition is True and y where it is False
np.where(condition, x, y) returns an array selecting elements from x when condition is True and from y when it is False.
Question 4: Which pandas dtype is assigned to a column containing text strings by default?
- str
- category
- object (Correct answer)
- unicode
Correct answer: object
pandas stores text (string) data as the 'object' dtype by default, though a dedicated StringDtype is also available.
Question 5: What is the primary purpose of cross-validation in machine learning?
- To speed up model training on large datasets
- To estimate how well a model generalizes to unseen data without wasting samples (Correct answer)
- To automatically tune hyperparameters
- To convert categorical features into numeric ones
Correct answer: To estimate how well a model generalizes to unseen data without wasting samples
Cross-validation rotates which portion of data is used for validation, giving a more reliable generalization estimate than a single train/test split.
Question 6: In a box plot, what do the whiskers typically represent?
- The mean ± one standard deviation
- The full range (min to max) of the data
- Data within 1.5 × IQR from the quartiles (Correct answer)
- The 10th and 90th percentiles
Correct answer: Data within 1.5 × IQR from the quartiles
By default, box plot whiskers extend to the furthest data point still within 1.5 × IQR from Q1 or Q3; points beyond are plotted as outliers.
Question 7: What value does a Pearson correlation coefficient of -1 indicate?
- No linear relationship between the two variables
- A perfect positive linear relationship
- A perfect negative linear relationship (Correct answer)
- The variables are statistically independent
Correct answer: A perfect negative linear relationship
A Pearson r of -1 means the two variables have a perfect inverse linear relationship: as one increases, the other decreases proportionally.
In a list comprehension [x**2 for x in range(5) if x % 2 == 0], how many elements does the result contain?