Home etc Blogs ML.NET: The Cross-Platform Machine Learning Framework for .NET

ML.NET: The Cross-Platform Machine Learning Framework for .NET

0
730
ml.net

You can use all the knowledge, skills, code, and libraries you already have as a .NET developer to create custom ML models with ML.NET. In this article, we take a look at a few aspects of this machine learning framework.

MLOps is an area related to ML deployment and delivery while ML.NET is an open source machine learning platform based on .NET. Developers of .NET can develop ML models using languages like C# and F#. These models can be trained, tested, and used for prediction. The platform has automated machine learning (AutoML) tools like the ML.NET command line interface (CLI) and ML.NET Model BuilderSupport for scenarios like classification, regression, recommendation, and image identification.

Using ML.NET
.NET Core has to be installed to use ML.NET CLI. Let us first install the .NET SDK 3.1.413 version using the following command, as shown in Figure 1:

Installer in execution
Figure 1: Installer in execution
dotnet tool install -g mlnet

You can execute ML.NET CLI by running the following command:

~/.dotnet/tools/mlnet

Figure 2 shows the output when this command is executed.

Output of mlnet showing successful installation
Figure 2: Output of mlnet showing successful installation

ML modelling
ML.NET is used for identifying patterns, predictive analytics, feature extraction and real-time data analysis. The imdb_labelled.txt can be downloaded from https://archive.ics.uci.edu/ml/machine-learning-databases/00331/sentiment%20labelled%20sentences.zip.

The data snippet is shown below:

A very, very, very slow-moving, aimless movie about a distressed, drifting young man.  	0
Not sure who was more lost - the flat characters or the audience, nearly half of whom walked out.  	0
Attempting artiness with black & white and clever camera angles, the movie disappointed - became even more ridiculous - as the acting was poor and the plot and lines almost non-existent.  	0
Very little music or anything to speak of.  	0
The best scene in the movie was when Gerardo is trying to find a song that keeps running through his head.  	1
The rest of the movie lacks art, charm, meaning... If it’s about emptiness, it works I guess because it’s empty.  	0
Wasted two hours.  	0

The command used in ML.NET for classification is mentioned below, and Figure 3 shows the output.

mlnet classification --dataset “imdb_labelled.txt” --has-header false --label-col 1 --train-time 60

The code that is generated as an output will have the following:

1. SampleClassification folder
2. A .NET console app (SampleClassification.ConsoleApp) having a ModelBuilder.cs and a Program.cs.
3. A .NET Standard class library (SampleClassification.Model) has a ModelInput.cs, ModelOutput.cs, and MLModel.zip.

The console app can be executed by copying MLModel.zip from the Model folder to the ConsoleApp folder. This app gives the sentiment of the input sentence. The command for execution is:

dotnet run

ML training
Model training happens when the ML.NET lazy loading technique starts. This technique starts after calling the Fit() method. The estimator helps in creating a transformer after learning, while the input is the training data and the output of the transformer is the trained model.

ML testing
Machine learning data is split into training, testing, and validation data sets. The tests are done to validate the data. There are different test types, as mentioned below:

  • Invariance
  • Directional expectation
  • Minimum functionality

ML evaluation
You can collect the following metrics for the model using ML.NET:

  • Accuracy
  • Area under the curve (AUC)
  • R-Squared
  • Root Mean Squared Error (RMSE)
  • Recall
  • Precision
  • Confusion matrix
  • Learning
  • Regularisation
  • Batch size
  • Depth of layers

ML deployment
Code generated from the ML.NET CLI is checked into Git (source code management tool) and can be deployed on Azure or any other cloud with Windows OS. DevOps tools like Jenkins can be used to deploy the code and data from the Git repository.

Sample classification after execution of dotnet run
Figure 3: Sample classification after execution of dotnet run

ML.NET helps in creating an ML model that can be updated frequently to provide real-time predictions and hence the business value.

NO COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here