ageron / ageron/handson-ml

CH02: Use train_test_split instead of StratifiedShuffleSplit

Open
#385 5 comments 17 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
25.6k
Forks
12.7k
PR merge metrics
No merged PRs in 30d

Description

In CH02, the book uses StratifiedShuffleSplit to split data according to income category, maybe it's more user-friendly to use train_test_split
code from master:
```
from sklearn.model_selection import StratifiedShuffleSplit

split = StratifiedShuffleSplit(n_splits=1, test_size=0.2, random_state=42)
for train_index, test_index in split.split(housing, housing["income_cat"]):
strat_train_set = housing.loc[train_index]
strat_test_set = housing.loc[test_index]
```
updated version:
```
strat_train_set, strat_test_set = train_test_split(
housing, test_size=0.2, random_state=42, stratify=housing["income_cat"])
```
Thanks for the awesome book!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.