Search code examples
c#ml.netml.net-model-builder

Where to Specify Time to Train in ML.NET


I'm evaluating ML.NET Model Builder (Preview) 16.1.0.2027905. When I go to train, the Builder lets me specify "Time to train (seconds)" (See Picture):

enter image description here

However, when I get to Step#6 and generate the code, I can't seem to find where the "Time to train" is specified...

The ML.NET Builder creates this function for me automatically in the ModelBuilder.cs file:

    public static ITransformer TrainModel(MLContext mlContext, IDataView trainingDataView, IEstimator<ITransformer> trainingPipeline)
    {
        Console.WriteLine("=============== Training  model ===============");

        ITransformer model = trainingPipeline.Fit(trainingDataView);

        Console.WriteLine("=============== End of training process ===============");
        return model;
    }

but I looked in the debugger at the mlContext, trainingDataView, trainingPipeline objects and didn't immediately see where I can specify time to train. Also, I did a global text search for 3600 (which is the time I trained for) and I didn't find any interesting code that way.

Is there some easy way in ML.NET to specify "Time to train" in seconds?

I'm asking this question because I want to call ModelBuilder.TrainModel manually with a user specified training interval. I don't want to always be required to use the ML.NET Builder GUI to retrain my model.


Solution

  • The Model Builder uses AutoML behind the scenes. The code that it produces is the pure ML.NET API code so it wouldn't have a way to specify the training time.

    If you want to use that, you would need to use the AutoML API. With that it has a way to specify the training time. Here's the doc that shows it, but it would be something like the below code:

    var settings = new RegressionExperimentSettings
    {
        MaxExperimentTimeInSeconds = 20,
    };
    

    Here's a full sample on it which was used in this video.

    Hope that helps!