dotnet/machinelearning · error · ArgumentException
If provided, {nameof(samplingKeyColumnName)} must be the sam
Error message
If provided, {nameof(samplingKeyColumnName)} must be the same as {nameof(groupIdColumnName)} for Ranking Experiments What it means
Thrown by UserInputValidationUtil.ValidateSamplingKey when a ranking experiment specifies a samplingKeyColumnName that differs from the groupIdColumnName. In ML.NET AutoML ranking experiments, the sampling key controls stratified sampling and must align with the group identifier so each query group is sampled as a unit. Passing a different column would break ranking group semantics, so it is rejected eagerly.
Source
Thrown at src/Microsoft.ML.AutoML/Utils/UserInputValidationUtil.cs:65
public static void ValidateInferColumnsArgs(string path)
{
ValidatePath(path);
}
public static void ValidateNumberOfCVFoldsArg(uint numberOfCVFolds)
{
if (numberOfCVFolds <= 1)
{
throw new ArgumentException($"{nameof(numberOfCVFolds)} must be at least 2", nameof(numberOfCVFolds));
}
}
public static void ValidateSamplingKey(string samplingKeyColumnName, string groupIdColumnName, TaskKind task)
{
if (task == TaskKind.Ranking && samplingKeyColumnName != null && samplingKeyColumnName != groupIdColumnName)
{
throw new ArgumentException($"If provided, {nameof(samplingKeyColumnName)} must be the same as {nameof(groupIdColumnName)} for Ranking Experiments", samplingKeyColumnName);
}
}
private static void ValidateTrainData(IDataView trainData, ColumnInformation columnInformation)
{
if (trainData == null)
{
throw new ArgumentNullException(nameof(trainData), "Training data cannot be null");
}
if (DatasetDimensionsUtil.IsDataViewEmpty(trainData))
{
throw new ArgumentException("Training data has 0 rows", nameof(trainData));
}
foreach (var column in trainData.Schema)
{
if (column.Name == DefaultColumnNames.Features && column.Type.GetItemType() != NumberDataViewType.Single)View on GitHub (pinned to 7b76e69cf9)
Solutions
- Set samplingKeyColumnName equal to groupIdColumnName for ranking experiments
- Pass null (or omit) samplingKeyColumnName when running a ranking experiment
- If the intent was independent sampling, run the experiment as a different TaskKind (e.g. binary classification) where samplingKey may differ
Example fix
// before experimentSettings.SamplingKeyColumnName = "UserId"; experimentSettings.GroupIdColumnName = "QueryId"; // ranking: mismatch -> ArgumentException // after experimentSettings.GroupIdColumnName = "QueryId"; experimentSettings.SamplingKeyColumnName = experimentSettings.GroupIdColumnName; // must match
Defensive patterns
Strategy: validation
Validate before calling
if (taskKind == TaskKind.Ranking && samplingKey != null && samplingKey != groupId)
throw new ArgumentException("samplingKeyColumnName must equal groupIdColumnName for ranking"); Try / catch
try { experiment.Execute(trainData, colInfo); }
catch (ArgumentException ex) when (ex.Message.Contains("SamplingKey")) { /* fall back to groupId as sampling key */ } Prevention
- Always derive samplingKeyColumnName from groupIdColumnName for ranking tasks
- Centralize experiment settings construction in one factory method per TaskKind
- Validate ColumnInformation consistency in unit tests
When it happens
Trigger: Calling any AutoML experiment Execute/ExecuteAsync with TaskKind.Ranking while samplingKeyColumnName is non-null and not string-equal to groupIdColumnName.
Common situations: Setting a sampling key for variance reduction in binary classification and reusing the same settings in a ranking experiment; copy-pasted experiment configs where samplingKey was tuned independently of the group column; misunderstanding that sampling key and ranking group id must coincide.
Related errors
- Training data cannot be null
- Training data has 0 rows
- {DefaultColumnNames.Features} column must be of data type {N
- Only supported feature column types are {BooleanDataViewType
- Duplicate column name {duplicateColName} is present in two o
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/a597644f1999111c.
Report an issue: GitHub.