dotnet / dotnet/docs

MLNET: Cross validation example does not finish processing

Open
#38,884 0 comments 0 reactions 0 assignees View on GitHub
:watch: Not Triaged dotnet-ml/svc
Dominant language
No language data
Stars
4.8k
Forks
6.1k
Avg merge
15h 21m
Merged PRs (30d)
370

Description

### Type of issue

Code doesn't work

### Description

Hi

I run example from this page https://learn.microsoft.com/en-us/dotnet/machine-learning/how-to-guides/train-machine-learning-model-cross-validation-ml-net using the following code but cross validation process never ends. I think the example should be updated or it should be explained that it can behave like this.

In file `data.csv` I have the same data like on the page with link above.

```
Console.WriteLine("Cross validation starting...");

MLContext mlContext = new MLContext(seed: 12345);
IDataView data = mlContext.Data.LoadFromTextFile("data.csv", separatorChar: ',', hasHeader: true);

// Define data prep estimator
IEstimator dataPrepEstimator =
mlContext.Transforms.Concatenate("Features", new string[] { "Size", "HistoricalPrices" })
.Append(mlContext.Transforms.NormalizeMinMax("Features"));

// Create data prep transformer
ITransformer dataPrepTransformer = dataPrepEstimator.Fit(data);

// Transform data
IDataView transformedData = dataPrepTransformer.Transform(data);

// Define StochasticDualCoordinateAscent algorithm estimator
IEstimator sdcaEstimator = mlContext.Regression.Trainers.Sdca();

// Apply 5-fold cross validation
Stopwatch sw = Stopwatch.StartNew();

var cvResults = mlContext.Regression.CrossValidate(transformedData, sdcaEstimator, numberOfFolds: 5);

Console.WriteLine(sw.ToString()); // ----------This line is never executed when I run it.---------------

// Select all models
ITransformer[] models =
cvResults
.OrderByDescending(fold => fold.Metrics.RSquared)
.Select(fold => fold.Model)
.ToArray();

// Get Top Model
ITransformer topModel = models[0];

Console.WriteLine("Finished");
```

### Page URL

https://learn.microsoft.com/en-us/dotnet/machine-learning/how-to-guides/train-machine-learning-model-cross-validation-ml-net

### Content source URL

https://github.com/dotnet/docs/blob/main/docs/machine-learning/how-to-guides/train-machine-learning-model-cross-validation-ml-net.md

### Document Version Independent Id

3c593c29-8e2f-9c88-26f6-c54a7345b6c7

### Article author

@luisquintanilla

### Metadata

* ID: df25ca43-b9af-7d37-1b6d-690183ab421d
* Product: **dotnet-ml**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.