You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Clarify samplingKeyColumnName docs and reject the label as AutoML sampling key - #7888
Users often pass their label column as samplingKeyColumnName and expect a stratified split. The sampling key does the opposite: rows that share a key value always land in the same subset, so grouping by the label puts every row of a class on the same side of the split (see #5563).
Changes
XML docs (no behavior change)
One shared wording for samplingKeyColumnName on every public API that takes it:
DataOperationsCatalog.TrainTestSplit and CrossValidationSplit
CrossValidate / CrossValidateNonCalibrated on the binary classification, multiclass classification, regression and clustering catalogs
RecommendationCatalog.CrossValidate, which called the parameter a "stratification column"
AutoML: ColumnInformation.SamplingKeyColumnName, the cross-validation ExperimentBase.Execute overload (now points to ColumnInformation.SamplingKeyColumnName like its sibling overload) and AutoMLExperiment.SetDataset
The new text says what the key is for (keeping related rows, such as all rows from the same user or session, together), says not to use the label column and why, and states that grouping is not stratification. It replaces "This can be used to ensure no label leakage from the train to the test set", which reads like a hint to pass the label.
AutoML validation
UserInputValidationUtil.ValidateSamplingKey now throws an ArgumentException when the sampling key column is the same as the label column, as suggested in the issue. ExperimentBase.Execute calls it before the data is split, so users get this error instead of a generic "all cross validation folds have empty train or test data" failure. No public API is added or changed.
New test: UserInputValidationTests.ExecuteThrowsWhenSamplingKeyIsLabel. It goes through both public Execute overloads (train/validate and cross-validation) with a constant label, so every fold would be one-sided if the data were split first.
Not included
No check in the core CrossValidate methods. They also receive labelColumnName, but throwing there would change the behavior of a stable API. I'm happy to add a warning or an exception there if you want it.
TrainTestSplit / CrossValidationSplit don't know the label column, so they only get the docs.
The warning for empty or unbalanced splits mentioned in the issue would need to count rows during the split, so I left it for a separate change.
BinaryClassificationExperiment, MulticlassClassificationExperiment and RegressionExperiment override Execute and currently don't use SamplingKeyColumnName at all (see the TODO in BinaryClassificationExperiment.Execute). The new check therefore applies to the experiments that use ExperimentBase.Execute (ranking and recommendation). Making the other experiments respect the sampling key looks like a separate issue; I can open one if that helps.
…pling key
Explain what the sampling key is for (keeping related rows together) and
that using the label column puts all rows with the same label in the same
subset. Use the same wording on every public API that takes it.
AutoML now throws an ArgumentException when the sampling key column is the
same as the label column.
Fixesdotnet#5567
The only failing leg is MacOS_x64 Release_Build: Microsoft.ML.Tests crashed with a segfault (exit code 139) while the FastTree / PFI / Cookbook tests were running (Helix log). This PR doesn't touch that code: the Microsoft.ML.Data and Recommender changes are XML docs only, and the new AutoML validation isn't used by Microsoft.ML.Tests. The MacOS_x64 legs have also failed recently on main and release/6.0. All other legs pass.
❌ Patch coverage is 90.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.85%. Comparing base (7d1d179) to head (31add50).
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Public Execute cross-validation paths split before validation, causing constant regression labels used as sampling keys to trigger a generic InvalidOperationException instead of the intended ArgumentException.
ExperimentBase.Execute splits the data before it validates the column
information, so a label used as the sampling key could fail with a generic
"all cross validation folds have empty train or test data" error. Move the
check into ValidateSamplingKey, which runs before the split, and test it
through both public Execute overloads.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The guard misses ranking’s default sampling-key path, leaving the empty-fold failure possible, and the new input restriction lacks required API approval.
When ranking uses GroupIdColumnName = "Label" and LabelColumnName = "Label" with SamplingKeyColumnName omitted, this guard passes even though GetSamplingKey uses the group column for splitting. A constant label therefore still produces the generic empty-fold exception. Compare the label against the effective ranking sampling key, including its default, and cover the omitted-key path in a regression test.
The reason will be displayed to describe this comment to others. Learn more.
Fair point. The issue asks for runtime checks but nobody approved this one, so I wrote it up as a proposal in the issue: #5567 (comment). Until a maintainer answers there I am leaving the check as it is, and I will drop it and keep this PR documentation-only if that is preferred.
On the ranking case from the same review (group id column equal to the label, sampling key omitted): the check compares the key the user passed, not the effective one. If the check is approved I will compare against the effective key and add a test for it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5567
Users often pass their label column as
samplingKeyColumnNameand expect a stratified split. The sampling key does the opposite: rows that share a key value always land in the same subset, so grouping by the label puts every row of a class on the same side of the split (see #5563).Changes
XML docs (no behavior change)
One shared wording for
samplingKeyColumnNameon every public API that takes it:DataOperationsCatalog.TrainTestSplitandCrossValidationSplitCrossValidate/CrossValidateNonCalibratedon the binary classification, multiclass classification, regression and clustering catalogsRecommendationCatalog.CrossValidate, which called the parameter a "stratification column"ColumnInformation.SamplingKeyColumnName, the cross-validationExperimentBase.Executeoverload (now points toColumnInformation.SamplingKeyColumnNamelike its sibling overload) andAutoMLExperiment.SetDatasetThe new text says what the key is for (keeping related rows, such as all rows from the same user or session, together), says not to use the label column and why, and states that grouping is not stratification. It replaces "This can be used to ensure no label leakage from the train to the test set", which reads like a hint to pass the label.
AutoML validation
UserInputValidationUtil.ValidateSamplingKeynow throws anArgumentExceptionwhen the sampling key column is the same as the label column, as suggested in the issue.ExperimentBase.Executecalls it before the data is split, so users get this error instead of a generic "all cross validation folds have empty train or test data" failure. No public API is added or changed.UserInputValidationTests.ExecuteThrowsWhenSamplingKeyIsLabel. It goes through both publicExecuteoverloads (train/validate and cross-validation) with a constant label, so every fold would be one-sided if the data were split first.Not included
CrossValidatemethods. They also receivelabelColumnName, but throwing there would change the behavior of a stable API. I'm happy to add a warning or an exception there if you want it.TrainTestSplit/CrossValidationSplitdon't know the label column, so they only get the docs.BinaryClassificationExperiment,MulticlassClassificationExperimentandRegressionExperimentoverrideExecuteand currently don't useSamplingKeyColumnNameat all (see theTODOinBinaryClassificationExperiment.Execute). The new check therefore applies to the experiments that useExperimentBase.Execute(ranking and recommendation). Making the other experiments respect the sampling key looks like a separate issue; I can open one if that helps.Checklist