>> Learn how to do serverless machine learning with ML.NET and
Azure functions in this episode of Azure Tips and Tricks.
We will build an application with the ML.NET Library,
that we'll be able to identify a type of
Irish flower based on data that we feed it.
Here we are in a normal command prompt in Windows.
I have .Net Core installed and also the Azure function tools.
You can install these by enabling the Azure and .Net Core
workloads in Visual Studio. Let's start.
First, I'll create a directory called demo, and go there.
Now, I'll create a new solution.
Next, I'll create a new console application
called model, and that's it.
Now, I'll add the model projects to the solution,
and I'll navigate to the model folder.
The model project will do the machine learning
training to create a machine learning model.
To do that, we need ML.NET.
So, I'll add a NuGet reference to ML.NET like this.
Just to be sure that all the packages are there,
I'll do a dotnet restore.
Now, for the training data,
let's first create a data directory for the data,
and I can get the data from here.
This URL contains a data file that has data about petal,
and sepal sizes, and which
flower these belonged to. Let's copy this.
Just to give you some better idea of what we are talking about,
the data represents the sizes of
petals and sepals of irish flowers.
Each type of iris has different sizes of
petals and sepals. All right.
I've switched over to Visual Studio Code,
where I've opened the solution that we've just created.
Here is the "Data" folder.
In here, I'll create a new file and call it irish-data.txt,
and I'll paste the data in, that's it.
Next, I need to create a data model class that can hold the data.
This is the irish data class,
and it looks like this.
A simple class that can hold the data.
I also need a class for the prediction data.
So, "New File", "IrishPrediction",
and here we go, and I'll paste this in.
This will hold the prediction labels.
Finally, I'll add a new file and call it "Model".
This class will contain the ML.NET code that actually
takes the training data and
creates a machine learning model from it.
It first loads the data from
the text file that it loads from the data path.
Next, it parses that data and prepares it for training.
Finally, it trains the model with the data,
which results in a model file which it writes to
the path that we set in the model path parameter.
Now, to hook it all up in the program class.
Here, we set the path to the data
and to where the model should be saved to.
Next, we train the model and test it.
Let's try it out in the terminal window.
First, I go to the "Model Folder".
Now, dotnet run model,
and there it goes.
It trains the model and tests it,
and here is the output.
Cool. Here's the model.zip file
which contains the machine learning model.
ML.NET is a really powerful library that allows you
to do machine learning with C#. Go check it out.