dotnet/machinelearning · error · ArgumentException

Validation data has 0 rows

Error message

Validation data has 0 rows

What it means

When validation (or test) data is supplied to an AutoML experiment, ValidateValidationData rejects it if the IDataView has zero rows, detected via DatasetDimensionsUtil.IsDataViewEmpty. An empty validation set yields no meaningful evaluation metrics, so the experiment is refused.

Source

Thrown at src/Microsoft.ML.AutoML/Utils/UserInputValidationUtil.cs:193

                throw new ArgumentException($"File '{path}' does not exist", nameof(path));
            }

            if (fileInfo.Length == 0)
            {
                throw new ArgumentException($"File at path '{path}' cannot be empty", nameof(path));
            }
        }

        private static void ValidateValidationData(IDataView trainData, IDataView validationData)
        {
            if (validationData == null)
            {
                return;
            }

            if (DatasetDimensionsUtil.IsDataViewEmpty(validationData))
            {
                throw new ArgumentException("Validation data has 0 rows", nameof(validationData));
            }

            const string schemaMismatchError = "Training data and validation data schemas do not match.";

            if (trainData.Schema.Count(c => !c.IsHidden) != validationData.Schema.Count(c => !c.IsHidden))
            {
                throw new ArgumentException($"{schemaMismatchError} Train data has '{trainData.Schema.Count}' columns," +
                    $"and validation data has '{validationData.Schema.Count}' columns.", nameof(validationData));
            }

            // Validate that every active column in the train data corresponds to an active column in the validation data.
            // (Indirectly, since we asserted above that the train and validation data have the same number of active columns, this also
            // ensures the reverse -- that every active column in the validation data corresponds to an active column in the train data.)
            foreach (var trainCol in trainData.Schema)
            {
                if (trainCol.IsHidden)
                {
                    continue;

View on GitHub (pinned to 7b76e69cf9)

Solutions

  1. Check `data.GetRowCursor(...).MoveNext()` or row count before passing as validationData.
  2. Reduce filter strictness or fix the split so the validation set has rows.
  3. For small datasets, use cross-validation instead of an explicit validation set.

Example fix

// before
var validationData = trainData.WhereFilter... // may be empty
context.AutoML(experimentSettings)... .Execute(trainData, validationData, ...);
// after
var rows = validationData.GetRowCursor(validationData.Schema).MoveNext();
if (!rows) throw new ArgumentException("validation data is empty");
result.Execute(trainData, validationData, ...);
Defensive patterns

Strategy: validation

Validate before calling

using var cursor = validationData.GetRowCursor(validationData.Schema);
bool hasRows = cursor.MoveNext();
if (!hasRows) throw new ArgumentException("validationData is empty");

Type guard

bool HasRows(IDataView data) => data.GetRowCursor(data.Schema).MoveNext();

Try / catch

try { result = experiment.Execute(trainData, validationData, columnInfo, settings); }
catch (ArgumentException ex) when (ex.Message.Contains("Validation data has 0 rows")) { /* fall back to cross-validation */ }

Prevention

When it happens

Trigger: Calling Experiment API (ValidateExperimentExecuteArgs) with a validationData IDataView built from an empty source — e.g. an empty train/test split, a filtered DataView whose predicate matched nothing, or an empty file loaded via LoadFromTextFile.

Common situations: Over-aggressive filters (e.g. `where row > allRows`); split fraction or seed yielding an empty holdout on tiny datasets; reading an empty CSV as validation data.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11). Data as JSON: /api/errors/8941cde1f7a7b6e8. Report an issue: GitHub.