-
Notifications
You must be signed in to change notification settings - Fork 6
Ensure equal sampling of age across cross validation folds #108
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ | |
| from sklearn.decomposition import PCA # type: ignore[import-not-found] | ||
| from sklearn.impute import SimpleImputer # type: ignore[import-not-found] | ||
| from sklearn.linear_model import LogisticRegression, Ridge # type: ignore[import-not-found] | ||
| from sklearn.model_selection import ShuffleSplit, StratifiedShuffleSplit, cross_validate # type: ignore[import-not-found] | ||
| from sklearn.model_selection import StratifiedShuffleSplit, cross_validate # type: ignore[import-not-found] | ||
| from sklearn.pipeline import Pipeline # type: ignore[import-not-found] | ||
| from sklearn.preprocessing import LabelEncoder, StandardScaler # type: ignore[import-not-found] | ||
|
|
||
|
|
@@ -51,7 +51,12 @@ def training_pipeline( | |
| else: | ||
| y_train = np.asarray(target_labels) | ||
| estimator = Ridge(alpha=1.0) | ||
| cv_strategy = ShuffleSplit(n_splits=n_splits, test_size=0.2, random_state=random_state) | ||
|
|
||
| bins = pd.qcut(y_train, q=5, labels=False, duplicates="drop") | ||
| cv_strategy = StratifiedShuffleSplit(n_splits=n_splits, test_size=0.2, random_state=random_state) | ||
| splits = list(cv_strategy.split(np.zeros_like(bins), bins)) | ||
| cv_strategy = splits | ||
|
Comment on lines
+55
to
+58
|
||
|
|
||
| scoring_metrics = {"mae": "neg_mean_absolute_error", "r2": "r2"} | ||
|
|
||
| pipe = Pipeline( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
np.zeros_like(bins)as a dummyXis non-obvious, and it depends onbinsshape/dtype semantics. Prefer a clearer placeholder that only encodes length (e.g.,np.empty((len(bins), 1))), and/or add a short comment explaining thatXis unused andbinssupplies the stratification labels.