Choose the best reason why missing values must be handled before training a model.
Think about what happens if the model sees empty or unknown data points.
Many machine learning algorithms cannot process missing values directly and may raise errors or produce unreliable results. Handling missing data ensures the model receives clean, consistent input.
Given the following code, what will be the resulting DataFrame?
import pandas as pd import numpy as np df = pd.DataFrame({'A': [1, np.nan, 3], 'B': [4, 5, np.nan]}) df_filled = df.fillna(df.mean()) print(df_filled)
Calculate the mean of each column ignoring NaNs, then replace NaNs with those means.
The mean of column A is (1 + 3) / 2 = 2.0, and for B is (4 + 5) / 2 = 4.5. Missing values are replaced accordingly.
Choose the model that can handle missing values internally without needing to fill them first.
Think about models that split data based on feature values and can branch around missing data.
Decision Trees can handle missing values by learning splits that consider missingness or by surrogate splits, unlike models that require complete data.
What is the most likely effect on accuracy if missing values are dropped from the test set but not from the training set?
Consider how removing test samples with missing data changes the difficulty of the test set.
Dropping missing values from the test set can remove harder or ambiguous cases, making the test set easier and inflating accuracy compared to training conditions.
Examine the code below and select the error it produces when run.
from sklearn.impute import SimpleImputer import numpy as np X = np.array([[1, 2], [np.nan, 3], [7, 6]]) imputer = SimpleImputer(strategy='median') X_imputed = imputer.fit_transform(X) print(X_imputed)
Check if the input array is numeric and if the median strategy is valid.
The input array is numeric, so median imputation works fine. The median of first column ignoring NaN is 4.0, so NaN is replaced by 4.0.
