Previous lesson. Common Pitfalls and Best Practices in Machine Learning · Next lesson. Your First ML Project: Step-by-Step Tutorial
Module 02 Exercise Pack
ML workflow. Train and test split. Simple fit and score.
How to run
From this exercises/ folder:
python solutions.py
That loads your implementations (in solutions.py) and runs the asserts in tasks.py.
Work pattern:
- Read each
exercise_N_...docstring intasks.py. - Implement the same function names in
solutions.py(starter solutions are already filled). - Re-run
python solutions.pyuntil you see the module OK line.
Deps: numpy, pandas, and scikit-learn where noted. No dataset downloads.
Tasks
- Split the toy matrix into train and test (80/20, fixed seed).
- Fit logistic regression and report test accuracy.
- Count features (columns) on X.
- Compute the minority class fraction.
- Confirm train and test are both nonempty after the split.
- Predict integer labels on the test set.
Hub smoke (do not edit)
CI runs the fence below from the hub repo root.
import runpy
import sys
from pathlib import Path
p = Path("road-to-machine-learning/02-introduction-to-ml/exercises/solutions.py").resolve()
sys.path.insert(0, str(p.parent))
runpy.run_path(str(p), run_name="__main__")
print("mod02-exercises-smoke OK")
Previous lesson. Common Pitfalls and Best Practices in Machine Learning · Next lesson. Your First ML Project: Step-by-Step Tutorial