Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shuffle as boolean while converting dataset to dataclass #1213

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion skrub/datasets/_fetching.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from sklearn import __version__ as sklearn_version
from sklearn.datasets import fetch_openml
from sklearn.datasets._base import _sha256
from sklearn.utils import Bunch
from sklearn.utils import Bunch, shuffle
from sklearn.utils.fixes import parse_version

from skrub._utils import import_optional_dependency
Expand Down Expand Up @@ -651,6 +651,7 @@ def _fetch_dataset_as_dataclass(
dataset_id: int | str,
target: str | None,
load_dataframe: bool,
shuffling: bool | bool = False,
data_directory: Path | str | None = None,
read_csv_kwargs: dict | None = None,
) -> DatasetAll | DatasetInfoOnly:
Expand Down Expand Up @@ -702,6 +703,8 @@ def _fetch_dataset_as_dataclass(
df = pd.read_parquet(info["path"])
else:
df = pd.read_csv(info["path"], **read_csv_kwargs)
if shuffling:
df = shuffle(df, random_state=42).reset_index(drop=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the random state should be a function parameter, as it would allow for control for multiple seeds during testing and more fine-grained control on reproducibility.

I'm not 100% sure we should reset indices, because it could be surprising for users. WDYT?

y = df[target]
X = df.drop(target, axis="columns")
dataset = DatasetAll(
Expand Down Expand Up @@ -777,6 +780,7 @@ def fetch_employee_salaries(
dataset_name="Employee salaries",
dataset_id=EMPLOYEE_SALARIES_ID,
target="current_annual_salary",
shuffling=True,
read_csv_kwargs={
"quotechar": "'",
"escapechar": "\\",
Expand Down
Loading