Home / ML Associate practice test / Data Processing / Question

Databricks Machine Learning Associate · free practice question

A data scientist is preparing features for a linear regression model. The dataset contains a subscription_tier column with 3 nominal categories: 'Bronze'…

Exam-style question on Data Processing from the free ML Associate practice test, with the answer and a full explanation below.

Updated November 10, 2026

Data Processing

A data scientist is preparing features for a linear regression model. The dataset contains a subscription_tier column with 3 nominal categories: 'Bronze', 'Silver', 'Gold'. There is no natural ordering among these tiers for this model's purpose. Which encoding strategy is most appropriate, and why?

  1. AUse ordinal integer encoding with Bronze=1, Silver=2, Gold=3, because linear regression reads the values as evenly spaced levels and learns one coefficient that scales with tier rank without adding redundant indicator columns
  2. BSkip encoding and pass the raw string column to the model, because Spark MLlib's LinearRegression converts string feature values to numeric TF-IDF weighted embeddings before fitting and manual encoding adds nothing
  3. CUse target (mean) encoding, because it outperforms one-hot encoding for linear models on nominal features with fewer than 10 categories and captures the label signal in one numeric column without added dimensions
  4. DUse StringIndexer alone without OneHotEncoder, because the indices 0, 1, and 2 are close enough in magnitude to binary indicators that the model learns a separate effect for each tier without the full transformation
  5. EUse StringIndexer followed by OneHotEncoder with dropLast=True to get 2 binary indicator columns, because integer codes for unordered tiers would impose a false linear ordering that the model would learn as a real gradient
Answer & explanation

Correct answer: E

WHY E: One-hot encoding is the appropriate strategy for nominal categorical features in linear regression. Integer encoding (0, 1, 2) would make the model learn a single slope implying that Bronze to Silver to Gold is a uniform linear increase, a false ordinal assumption. OHE creates independent binary indicators, so the model learns a separate additive effect for each tier. With 3 categories and dropLast=True, 2 binary columns are produced, which is sufficient to represent all 3 tiers.

WHY NOT A: Assigning 1/2/3 to nominal categories introduces a false ordinal relationship; linear regression treats the numeric gap between categories as a meaningful slope, which is incorrect for unordered data.

WHY NOT B: Spark MLlib's LinearRegression requires all features to be numeric; passing a string column raises a runtime error, and there is no internal string-to-embedding conversion.

WHY NOT C: Target encoding can be effective, but the blanket claim that it outperforms OHE for linear models is false; it can introduce data leakage if not implemented with cross-fitting, and OHE is the standard reliable approach.

WHY NOT D: StringIndexer alone introduces the same false ordinal assumption; even with 3 categories the model treats the codes 0, 1, and 2 as numerically meaningful and learns incorrect coefficient magnitudes.

Take the full ML Associate practice test free →

Would you pass today?

This question is one of 45 in the free, timed Databricks Machine Learning Associate practice test. Take it and get a section-by-section score.

Start the free test →