Given a dataset, write the preprocessing and cleaning code, train a simple model in a framework of your choice, and report evaluation metrics (craft exercise)
Asked in the craft exercise stage. This is a multi-part, two-page prompt in CoderPad. Emphasise presentation of results and next steps.
Implement train_model(dataset, target_key). Each dataset row is a dictionary containing numeric feature values, with missing values represented by null, and a binary target. Remove exact duplicate rows, discard rows with a missing target, impute missing numeric features using training-set means, standardize features, and train a nearest-centroid classifier. Use a deterministic stratified holdout containing the last row from each class. Return accuracy, precision, recall, and F1, rounded to four decimal places.
def train_model(dataset, target_key):