BasicsValidationNumPyGoogleMetaAmazon
Problem
Implement simple_train_test_split(X, y, train_ratio=0.8) that splits feature matrix X and target array y into (X_train, X_test, y_train, y_test) using n_train = int(len(X) * train_ratio) without shuffling.
Why It Matters: Holding out an unseen test split prevents overfitting illusions and is mandatory before evaluating any supervised model.
Sample Inputs & Expected Outputs
Example 1 — 80/20 split on 5 rows
>>> simple_train_test_split([[1], [2], [3], [4], [5]], [10, 20, 30, 40, 50], train_ratio=0.8)
X_train=[[1],[2],[3],[4]], X_test=[[5]], y_train=[10,20,30,40], y_test=[50]
n_train = int(5 * 0.8) = 4 rows in train, 1 row in test.
Example 2 — 50/50 split on 4 rows
>>> simple_train_test_split([[1, 0], [2, 0], [3, 0], [4, 0]], [0, 1, 0, 1], train_ratio=0.5)
2 train rows, 2 test rows (in original order)
No shuffling — preserves sequential order.
Constraints & Edge Cases
- Preserve row order (no shuffling).
- Return
(X_train, X_test, y_train, y_test)as NumPy arrays.
Constraints & Evaluation Criteria
- Preserve row order (no shuffling).
- Return `(X_train, X_test, y_train, y_test)` as NumPy arrays.
Hints
Python 3⌘/Ctrl+Enter to Run · ⌘/Ctrl+Shift+Enter to Submit
Loading Code Editor...
+1 Hidden Submit Case
Input / Scenario
10 rows, train_ratio=0.8
Expected Output / Criteria
8 train rows, 2 test rows