Module Assessment
Overview
In this module, you learned the foundational concepts and practical skills of machine learning: what ML is and how it differs from traditional programming, the distinction between supervised and unsupervised learning, how to source and evaluate data, how to clean raw data for ML, and how to engineer features that models can actually use. This assessment asks you to demonstrate all of those skills together — building a complete data preparation pipeline from a raw dataset to a processed feature matrix ready for a model.
Complete the assessment using this Colaboratory notebook.
Learning Objectives
By the end of this assessment, you will have demonstrated the ability to:
- Show readiness for more complex ML modules.
- Demonstrate basic data prep and understanding of ML tasks.
Assessment Overview
You'll work with the Palmer Penguins dataset — a classic ML dataset with realistic data quality issues, categorical variables, and numeric features at different scales. Your task is to take it from raw to ready: cleaned, encoded, scaled, and split for supervised classification.
Skills Assessed
| Skill | Lessons covered |
|---|---|
| Identify the ML problem type | Supervised vs. Unsupervised |
| Load and inspect a dataset | Collecting Data |
| Handle missing values and duplicates | Cleaning Data |
| Drop irrelevant or leaking columns | Cleaning Data |
| Encode categorical variables | Feature Engineering |
| Scale numeric features | Feature Engineering |
| Create engineered features | Feature Engineering |
| Perform a stratified train/test split | Collecting Data, Feature Engineering |
Assemble a ColumnTransformer pipeline | Feature Engineering |
Starter Code
Use the included Colaboratory notebook to complete the tasks below. Submit the link for grading.
Coding Assessment
The Dataset
import pandas as pd
import seaborn as sns
df = sns.load_dataset("penguins")
print(df.shape)
print(df.head())
print(df.isnull().sum())
The penguins dataset contains 344 rows and these columns:
| Column | Description | Type |
|---|---|---|
species | Penguin species (Adelie, Chinstrap, Gentoo) | Categorical — this is the target |
island | Island where observed (Biscoe, Dream, Torgersen) | Categorical |
bill_length_mm | Bill length in millimeters | Numeric |
bill_depth_mm | Bill depth in millimeters | Numeric |
flipper_length_mm | Flipper length in millimeters | Numeric |
body_mass_g | Body mass in grams | Numeric |
sex | Penguin sex (Male, Female) | Categorical |
Task 1: Identify the ML Problem Type
In a markdown cell, answer the following:
- Is this a supervised or unsupervised learning problem? Why?
- Is this a classification or regression task? Why?
- Is this binary classification or multi-class classification? Why?
Task 2: Inspect and Clean the Data
Perform the following steps:
- Print the shape, data types, and missing value counts.
- Drop any duplicate rows.
- Handle missing values:
- For numeric columns (
bill_length_mm,bill_depth_mm,flipper_length_mm,body_mass_g): impute with the median. - For the categorical column
sex: impute with the mode.
- For numeric columns (
- After cleaning, confirm there are zero missing values with
df.isnull().sum().
# Your cleaning code here
Task 3: Define Features and Target
- Separate the features (
X) and target (y):y=speciesX= all other columns
- Perform a stratified train/test split: 80% train, 20% test,
random_state=42. - Print the shape of
X_trainandX_test. - Print the class distribution in
y_trainusingvalue_counts(normalize=True).
from sklearn.model_selection import train_test_split
# Your code here
Task 4: Engineer a New Feature
Before building the preprocessing pipeline, create one new feature on both X_train and X_test:
bill_ratio:bill_length_mmdivided bybill_depth_mm. This captures the shape of the bill regardless of absolute size.
# Add bill_ratio to X_train and X_test
X_train = X_train.copy()
X_test = X_test.copy()
X_train["bill_ratio"] = ...
X_test["bill_ratio"] = ...
Task 5: Build a ColumnTransformer Pipeline
Build a preprocessing pipeline using ColumnTransformer that:
- Numeric columns (
bill_length_mm,bill_depth_mm,flipper_length_mm,body_mass_g,bill_ratio): applyStandardScaler - Categorical columns (
island,sex): applyOneHotEncoder(drop="first", sparse_output=False)
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.pipeline import Pipeline
numeric_features = ["bill_length_mm", "bill_depth_mm",
"flipper_length_mm", "body_mass_g", "bill_ratio"]
categorical_features = ["island", "sex"]
# Build numeric_transformer, categorical_transformer, and preprocessor here
Fit the preprocessor on training data and transform both sets:
X_train_processed = preprocessor.fit_transform(X_train)
X_test_processed = preprocessor.transform(X_test)
print(f"Processed train shape: {X_train_processed.shape}")
print(f"Processed test shape: {X_test_processed.shape}")
Task 6: Verify the Output
After processing, confirm the following:
- No
NaNvalues exist inX_train_processed(hint:np.isnan(X_train_processed).sum()). - The numeric columns have approximately mean = 0 and std = 1. Compute the column-wise mean and standard deviation of the numeric portion of
X_train_processed. - Print how many total features are in the processed output and list what they represent (e.g., 5 scaled numeric + how many one-hot columns?).
Task 7: Reflection
In a markdown cell, answer the following questions:
- Why must the
ColumnTransformerbe fitted on training data only and then used to transform the test set — rather than being fitted on the full dataset? - You created
bill_ratioas an engineered feature. Propose one additional feature you could create from the existing columns and explain what signal you think it would capture. - The penguins dataset has three species. If you trained a model and it achieved 95% accuracy, but 40% of the rows are Adelie penguins — would accuracy alone be sufficient to evaluate the model? What other metric(s) might you look at?
Grading Rubric
| Task | Points | Criteria |
|---|---|---|
| Task 1: Problem identification | 10 | Correctly identifies supervised multi-class classification with justification |
| Task 2: Cleaning | 20 | Removes duplicates, imputes all missing values correctly, confirms zero NaN |
| Task 3: Train/test split | 15 | Correct stratified split, prints shapes and class balance |
| Task 4: Feature engineering | 15 | bill_ratio correctly computed on both train and test sets |
| Task 5: ColumnTransformer | 25 | Pipeline built correctly, fit on train only, transform applied to both sets |
| Task 6: Verification | 10 | Confirms no NaN, verifies scaled statistics, explains output shape |
| Task 7: Reflection | 5 | Thoughtful answers demonstrating conceptual understanding |
| Total | 100 |