Skip to main content
πŸ”’ Preview mode. The first 15 Foundations lessons are free; this one is Pro. Start a 7-day trial to unlock the editor, AI hints and the the rest of the curriculum. Card required, cancel any time in Dashboard.Start 7-day trial β†’
⚑
← Coursesβ€ΊData Science AppliedModule 2 Β· Cleaning & Feature Engineering Β· Recapβ€ΊπŸŽ― Review: Data Science module 2 recapscenario42 / 104
+80 XP
Task
Build `train_test_split_indices(n, test_pct, seed)` β€” the foundation of every train/test workflow: - `n` total indices (0 to n-1). - `test_pct` ∈ `[0, 1]` β†’ fraction in the test set. - `seed` β†’ deterministic shuffling. - Return tuple `(train_indices, test_indices)` (sorted ascending in each). - Test size = `int(n * test_pct)` (floor; e.g. 100*0.2 = 20). - Edge: `n == 0` β†’ `([], [])`; `test_pct == 0` β†’ all train; `test_pct == 1` β†’ all test. Deterministic seed makes tests reproducible β€” the #1 contract every interviewer asks about.
✏️ Write your code here
🐍
Loading Python...
One-time download (~1 MB). Then it runs instantly.
πŸ“Š Result
Press Run to see result...

πŸ’¬ Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…