1. Home
  2. Data Science
  3. Scikit-learn
  4. What does train_test_split(X, y, stratify=y) guarantee?

Added 30 Nov -0001

What does train_test_split(X, y, stratify=y) guarantee?

  1. The training and test sets keep approximately the same class proportions as the full dataset Correct answer
  2. Only samples with non-missing labels are used, and rows with NaN labels are dropped
  3. Each class appears exactly once in the test set, regardless of how many samples it has
  4. The split is reproducible without setting random_state, because stratification fixes the seed

Correct answer

A. The training and test sets keep approximately the same class proportions as the full dataset

16 views

MCQSEXAM

Explanation

Stratified splitting makes each subset's class distribution match the input, which protects rare classes from being absent from a small holdout. Without it a 2 percent positive class can vanish from a 100-row test set. It raises a clear error if a class has fewer than two members, and it does not make the split reproducible, which still needs random_state.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Scikit-learn MCQs

Practise all Scikit-learn MCQs

Similar MCQs