databricks Machine Learning Associate · Practice questions

Section 2: Data Processing Practice Questions

Review 10 sample questions with their correct answers and explanations. Sign up free to continue with the full topic quiz.

Sign up free for the full quiz

Question 1

Which code computes the approximate first and third quartiles of a column in a Spark DataFrame?

  1. q1, q3 = df.stat.quantile('income', [0.25, 0.75], relativeError=0.01)
  2. q1, q3 = df.approxQuantile('income', [0.25, 0.75], 0.01) — Correct
  3. q1, q3 = df.summary('income').first()
  4. 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?

  1. A histogram of each
  2. RMSE
  3. A contingency table and chi-square test — Correct
  4. 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?

  1. df.summary() — Correct
  2. df.printSchema()
  3. df.approxQuantile()
  4. 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?

  1. When the feature is categorical
  2. When the feature is normally distributed with no outliers
  3. When there are no missing values
  4. 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?

  1. log(x)
  2. log1p — Correct
  3. 1/x
  4. 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?

  1. They are always equal
  2. It uses ranks, capturing monotonic relationships — Correct
  3. Spearman only works for categorical features
  4. 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?

  1. imputer.fit(train_df.union(test_df)).transform(test_df)
  2. imputer.transform(train_df) imputer.transform(test_df)
  3. train_i = imputer.transform(train_df) test_i = imputer.transform(test_df) # Imputer needs no fit
  4. 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?

  1. It reduces training data size
  2. Duplicates leak into the test set — Correct
  3. It removes the minority class
  4. 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?

  1. When the model is sensitive to extreme values
  2. When outliers are data entry errors
  3. When the outliers come from a broken sensor
  4. 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?

  1. It requires the values to be sorted
  2. It creates a huge sparse feature space — Correct
  3. One-hot encoding only works on numeric columns
  4. 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.

Ready for the full quiz?

Create a free QuizAnalyst account to practice the complete question set and save your progress.

Sign up free for the full quiz