Missing values are data points that are not recorded or are absent in a dataset. They can happen due to errors, skipped questions, or data loss.
Click to reveal answer
beginner
Name two simple methods to handle missing values.
Two simple methods are: 1) Removing rows or columns with missing values, 2) Filling missing values with a fixed value like mean, median, or mode.
Click to reveal answer
intermediate
Why is it sometimes better to fill missing values instead of removing them?
Filling missing values keeps more data for learning, which can improve model accuracy. Removing too many rows or columns can lose important information.
Click to reveal answer
beginner
What is mean imputation?
Mean imputation replaces missing values in a numeric column with the average (mean) of the available values in that column.
Click to reveal answer
intermediate
What is a potential downside of using mean imputation?
Mean imputation can reduce data variability and may bias the model because it ignores the natural spread of data and relationships between features.
Click to reveal answer
What does 'dropping missing values' mean?
AReplacing missing values with zeros
BRemoving rows or columns that contain missing data
CIgnoring missing values during training
DPredicting missing values using a model
✗ Incorrect
Dropping missing values means removing rows or columns that have missing data to avoid problems during analysis.
Which method fills missing numeric values with the average of the column?
AMean imputation
BMedian imputation
CMode imputation
DForward fill
✗ Incorrect
Mean imputation replaces missing numeric values with the average (mean) of the available values.
Why might removing all rows with missing values be a bad idea?
AIt fills missing values automatically
BIt always improves model accuracy
CIt can cause loss of too much data
DIt changes the data types
✗ Incorrect
Removing rows with missing values can cause loss of important data, reducing the amount of information available for learning.
Which of these is NOT a common way to fill missing values?
AUsing mean or median
BUsing mode for categorical data
CUsing random noise
DDropping the entire dataset
✗ Incorrect
Dropping the entire dataset is not a method to handle missing values; it would discard all data.
What is a risk of using mean imputation?
AIt can bias the model by reducing variability
BIt removes all missing values permanently
CIt increases data variability
DIt only works for categorical data
✗ Incorrect
Mean imputation reduces variability by replacing missing values with the same average, which can bias the model.
Explain why handling missing values is important before training a machine learning model.
Think about what happens if the model sees empty spots in data.
You got /3 concepts.
Describe two common techniques to handle missing values and when you might use each.
Consider small vs large amounts of missing data.
You got /3 concepts.
Practice
(1/5)
1. What is the main reason to handle missing values before training a machine learning model?
easy
A. Missing values are automatically ignored by all models
B. Missing values can cause errors or reduce model accuracy
C. Missing values improve model training speed
D. Missing values increase the size of the dataset
Solution
Step 1: Understand the impact of missing values
Missing values can cause errors or confuse the model, leading to poor predictions.
Step 2: Recognize model requirements
Most machine learning models require complete data without missing values to work properly.
Final Answer:
Missing values can cause errors or reduce model accuracy -> Option B
Quick Check:
Missing values harm model accuracy = D [OK]
Hint: Missing data breaks models, so fix it first [OK]
Common Mistakes:
Thinking missing values speed up training
Assuming models ignore missing data automatically
Believing missing values increase dataset size
2. Which of the following is the correct way to import and use SimpleImputer from scikit-learn to fill missing values with the mean?
easy
A. from sklearn.impute import SimpleImputer\nimputer = SimpleImputer(method='mean')
B. import SimpleImputer from sklearn.impute\nimputer = SimpleImputer('mean')
C. from sklearn.imputer import SimpleImputer\nimputer = SimpleImputer(strategy=mean)
D. from sklearn.impute import SimpleImputer\nimputer = SimpleImputer(strategy='mean')
Solution
Step 1: Check import syntax
The correct import is 'from sklearn.impute import SimpleImputer'.
Step 2: Check SimpleImputer initialization
The strategy parameter must be a string like 'mean', so strategy='mean' is correct.
Final Answer:
from sklearn.impute import SimpleImputer\nimputer = SimpleImputer(strategy='mean') -> Option D
Quick Check:
Correct import and strategy syntax = A [OK]
Hint: Use strategy='mean' and correct import syntax [OK]
Common Mistakes:
Using 'method' instead of 'strategy'
Not quoting 'mean' as a string
Wrong import statement syntax
3. Given the following code, what will be the output of print(X_imputed)?
import numpy as np
from sklearn.impute import SimpleImputer
X = np.array([[1, 2], [np.nan, 3], [7, np.nan]])
imputer = SimpleImputer(strategy='mean')
imputer.fit(X)
X_imputed = imputer.transform(X)
print(X_imputed)
SimpleImputer requires fit() before transform() to learn statistics from data.
Step 2: Verify data and strategy
Strategy 'median' is valid; None is accepted as missing; 2D list is acceptable.
Final Answer:
Missing fit() call before transform() -> Option C
Quick Check:
fit() must precede transform() = A [OK]
Hint: Always fit before transform with SimpleImputer [OK]
Common Mistakes:
Calling transform without fit
Confusing strategy names
Thinking None is invalid missing value
5. You have a training set with missing values and a test set with missing values in the same columns. What is the best practice to handle missing values before training and evaluating a model?
hard
A. Fit the imputer on training data, then transform both training and test data
B. Fit the imputer separately on training and test data
C. Fill missing values in test data with zeros, training data with mean
D. Remove all rows with missing values from both datasets
Solution
Step 1: Understand data leakage risk
Fitting imputer separately on test data leaks information from test set, causing biased evaluation.
Step 2: Apply consistent imputation
Fit imputer only on training data to learn statistics, then apply same transformation to test data.
Final Answer:
Fit the imputer on training data, then transform both training and test data -> Option A
Quick Check:
Fit on train, transform both = C [OK]
Hint: Fit imputer on train only, then transform test [OK]
Common Mistakes:
Fitting imputer separately on test data
Filling test missing values with zeros arbitrarily
Dropping too much data unnecessarily
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.