#MLNET – How to use the AutoML API in a Console App

Hi !

In my last posts I was testing AutoML using the Model Builder inside Visual Studio and also the CLI commands. There is also an API to use this in a .Net app, and the usage is very simple.

It all start, of course, adding the [Microsoft.ML.AutoML] nuget package

I read the documentation in [How to use the ML.NET automated machine learning API], and I created the following sample using the same data as in my previous posts.

The final result displays the results for each one of the tests and showcase the top 3 ranked models. This time LightGBM Trainer is one more time the best trainer to choose.

There is a full set of samples in the Machine Learning .Net Samples repository. I’ve reused some classes from the Common folder.

The complete source code is available https://github.com/elbruno/Blog/tree/master/20190516%20MLNET%20AutoML%20API

Happy Coding!

Greetings @ Toronto

El Bruno

References

Advertisements

#MLNET – Testing Machine Learning Model Builder preview. It’s so cool !

Hi !

Last week Machine Learning.Net 1.0 was officially announced during Build 2019, and the ML.Net team also announced a set of ML tools related to ML.Net.

One of the most interesting ones is Machine Learning Model Builder. You can get more information about Model Builder in the official website.

ML.NET Model Builder provides an easy to understand visual interface to build, train, and deploy custom machine learning models. Prior machine learning expertise is not required. Model Builder supports AutoML, which automatically explores different machine learning algorithms and settings to help you find the one that best suits your scenario.

Machine Learning Model Builder

The tool is on Preview, but it’s still an amazing one to play around with ML. So I decided to give it a try with my small data set of kids, the one I use on the Machine Learning.Net demos.

The structure of my CSV file is very simple with just 3 columns: Age, Gender and Label.

However the first time I run the scenario I found the following error.

Inferring Columns ...
Creating Data loader ...
Loading data ...
Exploring multiple ML algorithms and settings to find you the best model for ML task: regression
For further learning check: https://aka.ms/mlnet-cli
|     Trainer                             RSquared Absolute-loss Squared-loss RMS-loss  Duration #Iteration      |
[Source=AutoML, Kind=Trace] Channel started
Exception occured while exploring pipelines:
Provided label column 'Label' was of type String, but only type Single is allowed.
System.ArgumentException: Provided label column 'Label' was of type String, but only type Single is allowed.
   at Microsoft.ML.CLI.Program.<>c__DisplayClass1_0.<Main>b__0(NewCommandSettings options)
   at Microsoft.ML.CLI.CodeGenerator.CodeGenerationHelper.GenerateCode()
Please see the log file for more info.
Exiting ...

Which makes a lot of sense, my Label column is a String and the Model Builder expects a Single data type. So, I updated my data file replacing the labels with numbers and I was ready for a 2nd test.

This time the training process started fine, however I noticed that using just a small training dataset didn’t trigger any comparing between different algorithms. So I created a much bigger training dataset, and now I got the training process up and running.

At the end the results are the ones below. And it’s very interesting. I do most of my demos using a MultiClass SDCA trainer and AutoML suggest me to use a LightGBM trainer. This will be part of my Machine Learning.Net speech for sure in the future.

You can download the Visual Studio extension from https://dotnet.microsoft.com/apps/machinelearning-ai/ml-dotnet/model-builder and remember that we can talk about this on the Visual Studio 2019 event with the Mississauga .Net User Group in a couple of weeks!

Happy Coding!

Greetings @ Toronto

El Bruno

#MLNET – Error ‘Entry point ‘Trainers.LightGbmClassifier’ not found’ and how to fix it

Hi!

Monday Tip hoping to save you some time if someone finds this error

I1

System.InvalidOperationException: ‘Entry point ‘Trainers.LightGbmClassifier’ not found’

Before going on, let me share a little context. In the current version of Machine Learning.Net [0.3.0] we have a couple of new Trainers. One of them is LightGBM. This Framework allows us to perform supervised sorting tasks in binary mode, multiple categories and more. In the MSDN blog post for the version 0.3.0 of ML.Net, this framework is well described, with also a very interesting definition

The definition for LightGBM in ‘Machine Learning lingo’ is: A high-performance gradient boosting framework based on decision tree algorithms.

Well after choosing a test data set which I know well, I decided to move on and try this new Trainer. Once I had created all the infrastructure necessary to use the Framework, I found the error I mentioned at the beginning of the post. And I didn’t like it at all. If you know a little bit of Windows, you know that type errors [Entry Point] never predict anything good.

Well, it was time to start investigating what was going on. I will not enumerate all the steps and tests I did, but only comment that I get to download and debug the source code of Machine Learning.Net. Although as usually happens in these cases, the solution was much simpler. Just look at the following lines of code

I2

You have to download a NuGet package to use LightBGM!

15 seconds later I had everything up and running to try the new Trainer!

I3

Happy Coding!

Greetings @ Toronto

El Bruno

References

My Posts

#MLNET – Error ‘Entry point ‘Trainers.LightGbmClassifier’ not found’ y como solucionarlo

Buenas!

Tip de lunes con la esperanza de ahorrarle un poco de tiempo si alguien se encuentra este error

I1

System.InvalidOperationException: ‘Entry point ‘Trainers.LightGbmClassifier’ not found’

Antes de seguir un poco de contexto. En la version actual de Machine Learning.Net [0.3.0] tenemos varios nuevos trainers y uno de ellos es LightGBM. Este framework nos permite realizar tareas supervisadas de clasificación en modo binario, multiples categorías y varias opciones mas. En el post de introducción a la version 0.3.0 de ML.Net se presenta el mismo, y además con una definición bastante interesante

The definition for LightGBM in ‘Machine Learning lingo’ is: A high-performance gradient boosting framework based on decision tree algorithms.

Pues bien, después de elegir un set de datos de prueba que conozco bastante bien, me decidi a probar este trainer. Una vez que hube creado toda la infraestructura necesaria para utilizar el framework, me encontré con el error que menciono al principio del post. Y no me gusto nada. Si conoces un poco de Windows, sabes que los errores de tipo [Entry point], nunca auguran nada bueno.

Pues bien, fue el momento de comenzar a investigar que pasaba. No voy a enumerar todos los pasos y pruebas que hice, pero solo comentare que llegue a descargar y depurar el source code de Machine Learning.Net. Aunque como suele suceder en estos casos, la solución era mucho más simple. Solo hay que ver las siguientes líneas de código

I2

Hay que descargar un paquete NuGet para utilizar LightBGM!

15 segundos después ya tenia todo up and running para probar el nuevo trainer!

I3

Happy Coding!

Greetings @ Toronto

El Bruno

References

My Posts