Repository navigation
Conversation
Adds a gallery example demonstrating how to implement a custom cross-validation splitter, as suggested in scikit-learn#28828.
|
Thank you for opening your first pull request to scikit-learn! 🎉 To help get your contribution reviewed, please make sure that:
|
❌ Linting issuesThis PR is introducing linting issues. Here's a summary of the issues. Note that you can avoid having linting issues by enabling You can see the details of the linting issues under the
|
|
This PR could be reviewed as part of the sprints at EuroPython/EuroScipy, for a participant interested in trying yourself at reviewing. |
PranavAchar01
left a comment
There was a problem hiding this comment.
Thanks for putting this together, a worked example for custom splitters is a nice addition. I ran it locally and it does work end to end. A few things I noticed:
The example emits a ConvergenceWarning. LogisticRegression with the default max_iter=100 does not converge on unscaled iris, so building the gallery prints lbfgs failed to converge after 100 iteration(s). max_iter=1000 clears it.
random_state=42 has no effect here. Per the docstring it is only used when solver is 'sag', 'saga' or 'liblinear', and the default is 'lbfgs'. In a teaching example it may suggest the fit is stochastic when it is not.
The folds end up nearly single-class. iris is ordered by target and the splitter takes contiguous blocks, so with n_folds=5 the test folds are:
fold 0: {0: 30}
fold 1: {0: 20, 1: 10}
fold 2: {1: 30}
fold 3: {1: 10, 2: 20}
fold 4: {2: 30}
Nothing breaks (mean 0.927, versus 0.973 for StratifiedKFold), but a reader copying the pattern onto their own ordered data could get a misleading estimate without realising why. A sentence noting that contiguous folds assume the data is not ordered by the target, or shuffling the indices, would make the lesson safer.
Minor: in split, the comprehension reuses the loop variable name:
for split_idx, split in enumerate(splits):
train_idxs = np.concatenate(
[split for idx, split in enumerate(splits) if idx != split_idx]
)This is correct in Python 3 since the comprehension has its own scope, but it is a double take when reading.
|
Hi @moeahmed-github are you still working on this one? Do you mind if I take over? |
|
Hi @ArturoAmorQ feel free to take over |
Adds a gallery example demonstrating how to implement a custom cross-validation splitter, as suggested in #28828.
Reference Issues/PRs
What does this implement/fix? Explain your changes.
First time contributor introduction
AI usage disclosure
I used AI assistance for:
Any other comments?