Question 1
Which code computes the approximate first and third quartiles of a column in a Spark DataFrame?
- q1, q3 = df.stat.quantile('income', [0.25, 0.75], relativeError=0.01)
- q1, q3 = df.approxQuantile('income', [0.25, 0.75], 0.01) — Correct
- q1, q3 = df.summary('income').first()
- q1, q3 = df.agg(percentile('income'))
Correct answer
q1, q3 = df.approxQuantile('income', [0.25, 0.75], 0.01)
Explanation
approxQuantile returns approximate quantiles with a relative error parameter.
Question 2
Which method is appropriate to assess whether two categorical features are associated?
- A histogram of each
- RMSE
- A contingency table and chi-square test — Correct
- Pearson correlation on the raw strings
Correct answer
A contingency table and chi-square test
Explanation
Chi-square tests (and measures such as Cramér's V) evaluate association between categorical variables.
Question 3
Which call computes count, mean, stddev, min, quartiles and max for all numeric columns of a Spark DataFrame?
- df.summary() — Correct
- df.printSchema()
- df.approxQuantile()
- df.describe('median')
Correct answer
df.summary()
Explanation
summary() returns descriptive statistics including the 25%, 50% and 75% percentiles. dbutils.data.summarize(df) shows an interactive profile.
Question 4
When is median imputation preferred over mean imputation for a numeric feature?
- When the feature is categorical
- When the feature is normally distributed with no outliers
- When there are no missing values
- When the data is skewed or has outliers — Correct
Correct answer
When the data is skewed or has outliers
Explanation
Outliers pull the mean; the median better represents the center of skewed distributions.
Question 5
A column contains zero values and is right-skewed. Which transformation avoids taking the log of zero?
- log(x)
- log1p — Correct
- 1/x
- x squared
Correct answer
log1p
Explanation
log1p handles zeros because log(1 + 0) = 0.
Question 6
Which statement about Spearman correlation compared with Pearson correlation is correct?
- They are always equal
- It uses ranks, capturing monotonic relationships — Correct
- Spearman only works for categorical features
- Spearman measures linear relationships only
Correct answer
It uses ranks, capturing monotonic relationships
Explanation
Spearman uses rank order, capturing monotonic non-linear relationships.
Question 7
Which code fits an Imputer on training data and applies it to test data?
- imputer.fit(train_df.union(test_df)).transform(test_df)
- imputer.transform(train_df)
imputer.transform(test_df)
- train_i = imputer.transform(train_df)
test_i = imputer.transform(test_df)
# Imputer needs no fit
- model = imputer.fit(train_df)
train_i = model.transform(train_df)
test_i = model.transform(test_df) — Correct
Correct answer
model = imputer.fit(train_df)
train_i = model.transform(train_df)
test_i = model.transform(test_df)
Explanation
Fitting on training data only and reusing the fitted model on test data avoids leakage. Imputer is an estimator and needs fit.
Question 8
What is a risk of oversampling the minority class before splitting data into train and test sets?
- It reduces training data size
- Duplicates leak into the test set — Correct
- It removes the minority class
- There is no risk
Correct answer
Duplicates leak into the test set
Explanation
Resampling should be applied to the training set only after splitting.
Question 9
When might removing outliers be inappropriate?
- When the model is sensitive to extreme values
- When outliers are data entry errors
- When the outliers come from a broken sensor
- When outliers are genuine signal, as in fraud — Correct
Correct answer
When outliers are genuine signal, as in fraud
Explanation
In anomaly or fraud detection, extreme values can be the signal itself.
Question 10
A feature zip_code has 40,000 distinct values. Why might one-hot encoding be inappropriate?
- It requires the values to be sorted
- It creates a huge sparse feature space — Correct
- One-hot encoding only works on numeric columns
- It would reduce the number of features
Correct answer
It creates a huge sparse feature space
Explanation
High-cardinality one-hot encoding produces many sparse columns; alternatives include target encoding, hashing or grouping.