DEV Community

Cover image for Why use ML.NET?
Matt Eland
Matt Eland Subscriber

Posted on • Originally published at mattonml.net

Why use ML.NET?

In this short article we'll cover why you should use ML.NET, Microsoft's open-source machine learning and AI framework.

ML.NET is Production Ready

When organizations want to start adding machine learning or AI to their technical stack, the conversation often turns to other languages like Python or R. Typically organizations moving to AI / ML for the first time aren't sure how to get started and so they look at the popular libraries and languages, such as SciKit-Learn and Python.

While these libraries and languages are powerful and there are certainly many resources available to them, the difference between the programming languages and frameworks organizations use to power their existing applications and those languages used to train models can make model deployment and maintenance difficult.

Python as a separate tech stack and skillset your team needs to worry about

ML.NET allows you to use .NET for as much of your data science stack as you'd like, from data analysis to model training and evaluation to model deployment, inferencing, and MLOps maintenance.

Using ML.NET you can analyze datasets, train models, evaluate model performance, generate new predictions, build generative AI applications, and more - all in the same technologies you're using already.

Different ways of integrating ML.NET into your workflow

Most of ML.NET's capabilities can work completely disconnected from the internet using local data or locally stored models, meaning ML.NET can be an ideal option for on-device machine learning scenarios or scenarios involving critical security or cost factors.

For example, if you needed to make predictions on-device in offline or occasionally connected scenarios, you could use ML.NET to host a pre-trained model and run it locally regardless of internet connection.

Alternatively, if you already have a suite of ASP .NET application or API servers and you wanted to add machine learning, you could host your model in your existing ASP .NET application using a PredictionEnginePool resource. Bundling model inferencing into your API both reduces costs from needing to run a separate server while increases overall performance due to eliminating network calls and their associated latency.

ML.NET is also incredibly fast at what it does and is getting faster with every release, as illustrated by Microsoft's recent announcements for ML.NET 3.0.

Finally, ML.NET is mature, having seen initial release in early 2019 and having been developed internally by Microsoft for over a decade before that. Microsoft has vetted these technologies, and has developed extensions specifically for ML.NET running in common .NET application scenarios such as inside of ASP .NET applications.

ML.NET is Developer Ready

ML.NET isn't just ready for your organization, it's fantastic for your development team.

I'm a software engineer with a strong .NET background. Five years ago I started focusing more heavily on AI and machine learning. Because of ML.NET I didn't have to leave my existing .NET skillset behind - though I've done a lot with Python and R and am comfortable in those areas now. I still work most comfortably in C# or F# and ML.NET let me continue to use the languages and tooling I knew and loved - while performing new types of tasks.

Because ML.NET was built for .NET developers, its syntax and conventions will be familiar to .NET developers. This means that those who take the same journey that I did and start adding AI and machine learning to their skillsets don't need to leave their .NET skills behind.

While I could go off and use Python on a new data science project, I don't have to. If I know I have a lot of C# or F# logic that I want to integrate into my model training or model deployment process, ML.NET is a great fit for me. Additionally, I can stay in Visual Studio, VS Code, or Rider and continue to be effective using my existing IDE.

Learning data science is a journey, and .NET developers with basic data science literacy may not yet be able to determine the optimal model trainers or appropriate hyperparameters for their machine learning tasks.

Thankfully ML.NET keeps this in mind and provides a number of helpful tools to ease developers into machine learning scenarios including:

  • The Visual Studio Model Builder, a wizard-based approach to machine learning that focuses on the tasks the developer wants to perform
  • A command line interface (CLI) designed to work similarly to the model builder
  • The AutoML library which allows developers to write minimal amounts of code and have AutoML evaluate a wide range of model trainers and hyperparameters to identify the best one.

At the other extreme, experienced developer / data scientists can fully customize the model training pipeline and take advantage of configurable hyperparameter tuning and broad sets of metrics and standard machine learning tools.

I can personally attest to ML.NET's ability to meet developer / data scientists where they are - and nudge them forward on their data science skills development, to the point where I wrote a book about it!

ML.NET is Versatile

Finally, lest you think that ML.NET was a watered-down framework missing key functionality, I'd encourage you to look over the list of built-in algorithms and trainers and supported machine learning tasks.

In traditional machine learning, ML.NET supports the following machine learning tasks:

  • Data Analysis (via DataFrame)
  • Regression (predicting a numerical value)
  • Forecasting (predicting numerical values over a region of time)
  • Binary Classification and Multiclass Classsification (predicting what category something is in)
  • Anomaly Detection (finding atypical individual data rows or groups of data rows)
  • Clustering (identifying clusters of rows with similar characteristics - useful for marketing and data analysis)
  • Ranking (predicting what rank order rows would fall into - useful for displaying search results)
  • Recommendation (suggesting new items based on a user's past preferences)
  • Image Classification (categorizing images into known categories based on their content)
  • Object Detection (identifying known objects inside of an image along with a region)

As you can see, ML.NET can do a lot. Each one of these tasks has multiple specific model trainers and sets of metrics inside of it designed for specific machine learning scenarios.

For those more interested in AI than ML, ML.NET supports many AI scenarios from probabilistic forecasting with Infer.NET to working with LLMs and other forms of generative AI.

ML.NET also integrates with Open Neural Network Exchange (ONNX) models, so you could train a model using SciKit-Learn, TensorFlow, or other frameworks, export the trained model to ONNX, import the model in ML.NET and use ML.NET just for model inferrencing.

Final thoughts on reasons for using ML.NET

The bottom line is that ML.NET is an incredible workhorse that Microsoft and the community continue to invest in year after year. In fact, ML.NET has major new releases coming alongside new versions of .NET itself with more features coming all the time.

ML.NET is not Python and it will likely never see the same size of community and abundance of resources as Python enjoys for machine learning. Additionally, there are some gap areas - particularly if you wanted to focus more on ML.NET's data analysis capabilities. These are areas I will be advocating for in future pieces - as well as potentially addressing with my own code submissions.

I expect ML.NET to continue to grow in maturity, effectiveness, and relevance and it will continue to be my default recommendation for most .NET development teams looking to add serious machine learning capabilities to their applications.

In fact, this post is my very first in a new series of content I'm starting on MattOnML.NET exploring the ins-and-outs of ML.NET, walking through a number of ML.NET projects, and generally showing you why this framework is particularly awesome to work with for fun as well as in your production applications. If you have a specific machine learning project you'd love to see me explore, please let me know!

For now, I hope I've given you some reasons to use ML.NET and see how deep and powerful this framework is.

Top comments (0)