How to Handle Missing Values in Linear Regression on SageMaker
A data scientist is using Amazon SageMaker to train a linear regression model. The training data contains missing values. Which TWO techniques are appropriate for handling missing values in the dataset?
Quick Answer
The answer is to impute missing values with the mean of the column or remove rows with missing values if the proportion is small. Imputation with the mean preserves the overall distribution of the feature, which is critical for linear regression because the model assumes a linear relationship and is sensitive to biased inputs. Removing rows is acceptable when the missing data is minimal and random, as it avoids distorting the coefficient estimates. On the AWS Certified Machine Learning Specialty MLS-C01 exam, this question tests your understanding that linear regression cannot inherently handle missing values—unlike tree-based models—so you must preprocess the data. A common trap is selecting “set missing values to zero,” which artificially shifts the intercept and biases the model. Remember the mnemonic: “Mean or drop, never zero or stop” to recall that imputation with the mean or deletion of sparse missing rows are the appropriate techniques for linear regression on SageMaker.
⚠ Common exam trap
The MLS-C01 exam often tests the misconception that any missing value handling technique is universally applicable, but the correct choice depends on the model type (e.g., linear regression vs. tree-based models) and the nature of the missing data (e.g., MCAR vs. MAR).
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Remove rows with missing values if the proportion is small
Removing rows with missing values is a straightforward and effective technique when the proportion of missing data is small (e.g., less than 5% of the total dataset). This avoids introducing bias or distorting the distribution, which is critical for linear regression models that assume complete and normally distributed data. In Amazon SageMaker, this can be done during data preprocessing using built-in transformations or custom scripts before training.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use a decision tree model that can handle missing values internally
Why it's wrong here
The question specifies linear regression, which cannot handle missing values natively.
- ✗
Set missing values to zero
Why it's wrong here
Setting to zero can introduce bias and is not recommended without reason.
- ✓
Remove rows with missing values if the proportion is small
Why this is correct
If a small fraction of rows have missing values, removing them is acceptable.
- ✓
Impute missing values with the mean of the column
Why this is correct
Mean imputation is a simple and common technique for numeric features.
- ✗
Create a separate category for missing values
Why it's wrong here
Creating a separate category for missing values is inappropriate for linear regression because the model requires numerical inputs for all features; a categorical placeholder like "Unknown" cannot be directly processed by the regression algorithm without encoding, which introduces ordinality that distorts the linear relationship. This technique is tempting because it works well for tree-based models (e.g., decision trees) that natively handle categorical splits on missing indicators, but linear regression lacks that branching mechanism.
Go deeper
Related to this question
About these practice questions
This MLS-C01 question is part of Courseiva's 1,672-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
Same concept, more angles
2 more ways this is tested on MLS-C01
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. A data scientist is using Amazon SageMaker to train a linear regression model. The training data contains missing values. Which preprocessing step should be applied before training?
easy- A.Ignore missing values; linear regression can handle them.
- ✓ B.Impute missing values with the mean of the column.
- C.Replace missing values with zeros.
- D.Remove all rows containing missing values.
Why B: Linear regression models in Amazon SageMaker cannot handle missing values natively; they require complete numerical input. Imputing missing values with the column mean is a standard preprocessing technique that preserves the overall distribution and avoids introducing bias, ensuring the SageMaker built-in Linear Learner algorithm can train without errors.
Variation 2. A data scientist is using Amazon SageMaker to train a linear regression model. The training job fails with the error: 'AlgorithmError: Input data has NaN values'. Which step should the data scientist take to resolve this issue?
medium- A.Convert the data to a sparse format
- B.Switch to a different algorithm that handles missing values
- ✓ C.Impute missing values or remove rows with NaN values
- D.Increase the number of training instances
Why C: The error 'AlgorithmError: Input data has NaN values' indicates missing values in the dataset. Linear regression cannot handle NaN values. The appropriate action is to either impute missing values (e.g., using mean/median) or remove rows with NaN values. Option A (convert to sparse format) is used for handling zero values, not missing values, and will not resolve NaN errors. Option B (switch to a different algorithm) is unnecessary because data preprocessing can fix the issue; moreover, many algorithms also cannot handle NaN. Option C is correct. Option D (increase training instances) only adds more compute resources and does not fix data quality issues.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This MLS-C01 practice question is part of Courseiva's free Amazon Web Services certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the MLS-C01 exam.