dotnet / machinelearning-samples

Samples for ML.NET, an open source and cross-platform machine learning framework for .NET.
https://dot.net/ml
MIT License
4.47k stars 2.68k forks source link

AutoML - how to read values of L1Regularization and L2Regularization and selected algorithm name? #1012

Open kicaj29 opened 9 months ago

kicaj29 commented 9 months ago

Hi

When I use VS designer to generate model it generates for example file MyModel.training.cs with such code which can be used to re-train model using the same paramters.

        public static IEstimator<ITransformer> BuildPipeline(MLContext mlContext)
        {
            // Data process configuration with pipeline data transformations
            var pipeline = mlContext.Transforms.Text.FeaturizeText(inputColumnName:@"col0",outputColumnName:@"col0")      
                                    .Append(mlContext.Transforms.Concatenate(@"Features", new []{@"col0"}))      
                                    .Append(mlContext.Transforms.Conversion.MapValueToKey(outputColumnName:@"col1",inputColumnName:@"col1",addKeyValueAnnotationsAsText:false))      
                                    .Append(mlContext.MulticlassClassification.Trainers.LightGbm(new LightGbmMulticlassTrainer.Options(){NumberOfLeaves=2717,NumberOfIterations=2632,MinimumExampleCountPerLeaf=29,LearningRate=0.0609179057439351,LabelColumnName=@"col1",FeatureColumnName=@"Features",ExampleWeightColumnName=null,Booster=new GradientBooster.Options(){SubsampleFraction=0.999999776672986,FeatureFraction=0.99999999,L1Regularization=1.67496587225263E-09,L2Regularization=0.999999776672986},MaximumBinCountPerFeature=207}))      
                                    .Append(mlContext.Transforms.Conversion.MapKeyToValue(outputColumnName:@"PredictedLabel",inputColumnName:@"PredictedLabel"));

            return pipeline;
        }

If I use AutoML TrialResult experimentResults = await experiment.RunAsync(); I cannot find there name of the algorithm and its params which have been used to generate this mode.

I found this doc https://learn.microsoft.com/en-us/dotnet/machine-learning/how-to-guides/train-machine-learning-model-ml-net#extract-model-parameters but in my case any casting ends with null value.

I was trying these casts but every time I see the null value

            model as TransformerChain<MulticlassPredictionTransformer<Microsoft.ML.Trainers.MaximumEntropyModelParameters>>
           model as TransformerChain<MulticlassPredictionTransformer<Microsoft.ML.Trainers.LinearMulticlassModelParameters>>
            model as TransformerChain<MulticlassPredictionTransformer<Microsoft.ML.Trainers.LinearMulticlassModelParametersBase>>