Ultimate access to all questions.
Upgrade Now 🚀
Sign in to unlock AI tutor
Consider a dataset with a numerical feature 'Age' having missing values. Write a code snippet to perform median imputation on this feature using Python and the scikit-learn library. Explain how this process handles missing values.
A
from sklearn.impute import SimpleImputer
imputer = SimpleImputer(strategy='median')
imputer.fit(df[['Age']])
df['Age'] = imputer.transform(df[['Age']])
B
imputer = SimpleImputer(strategy='mean')
C
imputer = SimpleImputer(strategy='mode')
D
imputer = SimpleImputer(strategy='constant', fill_value=0)