[BUG] Chapter 2, CV splits are not random as opposed to what is written
- Dominant language
- Jupyter Notebook
- Stars
- 14.1k
- Forks
- 5.3k
- PR merge metrics
- No merged PRs in 30d
Description
Notebook name: 02_end_to_end_machine_learning_project
Section 4.2 “Better Evaluation Using Cross-Validation”, cell 140
Book Chapter 2, subsection "Better Evaluation Using Cross-Validation".
According to the book the following code randomly splits the training set:
```
from sklearn.model_selection import cross_val_score
tree_rmses = -cross_val_score(tree_reg, housing, housing_labels,
scoring="neg_root_mean_squared_error", cv=10)
```
According to the documentation of [cross_val_score](https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.cross_val_score.html) (version 1.3.2) specifying an integer for the “cv” variable implies an internal use of (Stratified)KFold class with shuffle=False. Perhaps stating the obvious - to get randomization, one could pass a CV splitter instance as e.g. below:
```
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import KFold
forest_reg = make_pipeline(preprocessing,
RandomForestRegressor(random_state=42))
forest_rmses = -cross_val_score(forest_reg, housing, housing_labels,
scoring="neg_root_mean_squared_error", cv=KFold(n_splits=10, shuffle=True, random_state=42))
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.