Handling NaN Values in SageMaker Linear Regression
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?
Quick Answer
The error message here is unusually direct, it explicitly says the input data has NaN values, so this is really a data-quality problem being disguised as an algorithm error, not an issue with the SageMaker training job configuration itself. Linear regression, like many algorithms, requires every input to be a real number in order to compute its underlying matrix operations, so a missing value represented as NaN breaks that computation and causes the job to fail before meaningful training can even happen. The appropriate response is to handle the missing values during preprocessing, either by imputing them, commonly using a statistic like the mean or median of the column, or by removing the rows that contain them, both of which produce a dataset made entirely of valid numeric inputs that the algorithm can actually process. It's worth distinguishing this from a related but different situation, sparse data, where values are legitimately zero rather than missing, because converting to a sparse format solves a different problem and does nothing to eliminate an actual NaN value sitting in the dataset. Similarly, switching to a different algorithm doesn't inherently fix anything, since NaNs will still break most other algorithms; and adding more compute resources addresses capacity, not data validity, so it wouldn't touch the root cause here either. Whenever a training job error explicitly references missing or NaN values, treat it as a data preprocessing problem to solve with imputation or row removal, not an infrastructure or algorithm-selection problem.
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
✓
Impute missing values or remove rows with NaN values
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.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Convert the data to a sparse format
Why it's wrong here
Sparse format does not address NaN values; it is for zeros.
- ✗
Switch to a different algorithm that handles missing values
Why it's wrong here
The issue is data preprocessing, not algorithm selection.
- ✓
Impute missing values or remove rows with NaN values
Why this is correct
Handling missing values by imputation or removal resolves the NaN error.
- ✗
Increase the number of training instances
Why it's wrong here
Adding more instances does not remove NaN values from the data.
Visual reference
Go deeper
Related to this question
About these practice questions
Courseiva writes every MLS-C01 question from scratch — 1,672 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
Same concept, more angles
1 more way 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.
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.