How to use ML.NET to build machine learning models in .NET applications

Audacia
CodeX
5 min readMay 1, 2023

--

At Audacia, we have been using ML.NET to build robust machine learning models. ML.NET is a cross-platform framework that allows developers to create custom machine learning models using C# or F#. It is designed to be easy to use, even for developers without prior experience in creating machine learning models. One of the significant advantages of using ML.NET is that it is a part of .NET.

This article explores how Audacia has been using ML.NET to build fully-fledged machine learning models quickly and effectively. We will breakdown a real-world application of ML.NET in Audacia’s projects and the benefits it has brought to the development process.

Using ML.NET for a machine learning consultancy project

This project was centred around a sterilisation process for medical products. Sterilisation is a critical process in the medical industry, as it ensures that medical products are safe for patient use. The client, a leading provider of medical products and services, wanted to optimise their sterilisation process by accurately predicting the dosage range achieved for products receiving irradiation.

Audacia delivered a product dosage predictor which predicts the dose range achieved for various products during a manufacturing process. The goal was to optimise the scheduling of irradiation processes by accurately predicting the dosage range achieved for products receiving irradiation.

Audacia used ML.NET to build a linear regression model that would learn from years of historic dosage information. ML.NET provided us with a range of pre-built algorithms and models, as well as the flexibility to create custom models to meet the specific needs of the client.

The resulting model achieved over 97% accuracy, giving the client foresight necessary for planning that was not previously possible. With this tool, the client was able to optimise their scheduling process and reduce the likelihood of nonconformances.

Throughout the process, we worked closely with the client to ensure that the model was meeting their needs and that the results were accurate and reliable. The client was impressed with the capabilities of ML.NET and the potential of the solution to improve their product’s reliability and reduce maintenance costs.

Building the machine learning model with ML.NET

1. Defining the scenario

When working with ML.NET , the first step is to define the scenario that you want to solve with machine learning. For this project, we wanted to predict a single value based on a set of parameters. The model used for this project is, therefore, a linear regression model. Defining the scenario upfront helps to guide the rest of the process and ensures that the model that we are creating is well-suited to the problem at hand.

2. Selecting data and loading it into ML.NET

With our scenario defined, we can now select the data that will be used to train our model. ML.NET allows you to load data from a variety of sources, including CSV files and SQL Server databases. For larger datasets, loading from a database may be more efficient.

3. Training the model

At this stage, we select the appropriate machine learning algorithm and specify the parameters that you want to use. For this project, we used the LGM algorithm, which is a type of linear regression algorithm that is well-suited to predicting a single value based on a set of input parameters.

The parameters for this machine learning model were density, number of times the surrounding data types of density and the processing speeds. Models can be trained on a machine and ML.NET provides several built-in functions that make it easy to create and train your model.

4. Testing and evaluating the model

Functions like Test and Evaluate can be used to ensure that it is accurate and performing as expected. In ML.NET , these functions allow you to test your model on a set of data that it has not seen before and to evaluate its performance based on metrics like accuracy and precision.

5. Saving and using the model

Once you are satisfied with the performance of your model, you can save it for future use. ML.NET saves the model as a zip file on your file system, which can then be uploaded to Azure or used locally. The fact that ML.NET is built on .NET makes it easy to use the model in a variety of applications, regardless of the programming language that you are using.

Benefits of using ML.NET for machine learning projects

One of the key benefits of using ML.NET is that it allows for an iterative and agile process. Because the entire project is built on .NET, it is easy to make changes and update the model as needed. This means that you can quickly iterate and refine your model until you are satisfied with its performance.

Here are four key benefits:

1. Faster prototyping: With ML.NET , developers can quickly build and test machine learning models without having to worry about the complexities of traditional programming languages like Python, C++ or Ruby. This can save considerable time in the prototyping phase of a project, allowing developers to experiment and iterate more quickly.

2. Scalable: ML.NET can handle large data sets and is designed to work with distributed systems, making it scalable for use in enterprise-level applications. This means that developers using ML.NET can easily scale their models for production use.

3. Increased agility: Because of its seamless integration with .NET, ML.NET allows for an iterative and agile development process, allowing developers to quickly make changes and updates to the model as needed. This means that teams can easily collaborate and iterate on models, leading to faster development cycles and quicker time-to-market.

Additionally, ML.NET ‘s easy-to-use API and pre-built models enable developers to rapidly experiment and prototype with different machine learning scenarios, supplying a competitive advantage in the fast-paced world of software development.

4. Compatibility with existing infrastructure: ML.NET is built on .NET, which means that it can be easily integrated with your existing IT infrastructure. This can save your enterprise time and money by eliminating the need for a complete overhaul of your technology stack.

AI and ML development with ML.NET

Audacia continues to use the power of ML.NET to provide robust machine learning models for industry leading organisations. With a team of experienced developers who have a deep understanding of the ML.NET framework, Audacia can deliver solutions tailored to meet the unique needs of each client. Audacia can help your organisation leverage ML.NET to accelerate development and improve business outcomes.

Audacia is a software development company based in the UK, headquartered in Leeds. View more technical insights from our teams of consultants, business analysts, developers and testers on our technology insights blog. This article was written by Audacia Principal Consultant, Owen Lacey.

--

--

Audacia
CodeX
Writer for

Audacia is a leading UK software development company who specialises in building scalable and robust, business-critical software systems.