头图

This article briefly introduces the ML.NET background and features for .NET development, as well as typical machine learning coding examples, and shares my own ML.NET API quick reference manual.

Introduction

ML.NET is a cross-platform machine learning framework for .NET developers that provides the ability to integrate machine learning models into .NET applications in an online or local environment.

图片

In 2002, Microsoft started a research project named TMSN, which meant "Test mining search and navigation", and was later renamed TLC (The learning code). ML.NET is derived from the TLC library and was originally used in Microsoft's internal products.

The core of ML.NET can either train custom machine learning models by specifying algorithms, or import pre-trained TensorFlow and ONNX models to continue training. After the model is generated, it can be added to the application for prediction. ML.NET supports running on Windows, Linux, and macOS using .NET Core/.NET Framework, all platforms support 64-bit, and Windows platforms support 32-bit, with the exception of TensorFlow, LightGBM, and ONNX-related features.

ML.NET integrates many mainstream converters and algorithm libraries, provides rich data processing objects and algorithm evaluators through API, and provides convenience for machine learning related packages such as Infer.NET, NimbusML, Scikit-Learn, TensorFlow, etc. extension mechanism. If you are a .NET developer, you will easily get started and seamlessly integrate the results into .NET Core applications, especially ASP.NET Core web applications to implement some advanced intelligent services.

Logistic regression model example

A simple example of training a logistic regression model for binary classification is as follows:


//Step 1. Create an ML Context
var ctx = new MLContext();

//Step 2. Read in the input data from a text file for model training
IDataView trainingData = ctx.Data
    .LoadFromTextFile<ModelInput>(dataPath, hasHeader: true);

//Step 3. Build your data processing and training pipeline
var pipeline = ctx.Transforms.Text
    .FeaturizeText("Features", nameof(SentimentIssue.Text))
    .Append(ctx.BinaryClassification.Trainers
        .LbfgsLogisticRegression("Label", "Features"));

//Step 4. Train your model
ITransformer trainedModel = pipeline.Fit(trainingData);

//Step 5. Make predictions using your trained model
var predictionEngine = ctx.Model
    .CreatePredictionEngine<ModelInput, ModelOutput>(trainedModel);

var sampleStatement = new ModelInput() { Text = "This is a horrible movie" };

var prediction = predictionEngine.Predict(sampleStatement);

ML.NET is currently on Github as an open source project ( https://github.com/dotnet/machinelearning ) for continuous update iterations, and the latest version is 1.6.

ML.NET featured

The popular machine learning tasks supported by ML.NET cover many, including traditional classification, regression, clustering, and also supports related time series and image neural networks. Currently known application scenarios such as sentiment analysis, product recommendation, price prediction, customer stratification, object detection, fraud detection, peak detection, image classification, sales forecast, etc.

ML.NET is very friendly to .NET developers. It provides Visual Studio extension Model Builder, which is a visual tool suite that can quickly train machine learning models of specified task types with very low operating requirements, and automatically Generate relevant source code to facilitate subsequent modification and maintenance. For partners who like to perform machine learning tasks through code, the official provides rich documentation ( https://docs.microsoft.com/en-us/dotnet/machine-learning/ ) and sample code library ( https: //github.com/dotnet/machinelearning-samples ).

In addition, ML.NET also provides command-line tools for the CLI, and supports AutoML, enabling zero-coding for common machine learning scenarios.

Quick Reference Manual

The code generated by AutoML will be a little uncomfortable to read at first, and it is not conducive to the subsequent modification of the code to meet the actual needs of developers. Developers who have never been exposed to machine learning may be worried about not being able to remember, understand, or use the jargon-based objects and methods in the ML.NET API documentation, given the obstacles to collecting feedback from actual developers. , the author organizes the ML.NET API according to the classic machine learning implementation steps, organizes the commonly used methods into an atlas, and adds some code snippets to help quickly understand the usage rules of API objects and methods. In addition, at the bottom of the atlas, the model trainers and data converters that ML.NET has built-in support so far are listed in a table to facilitate complete information. The atlas is shared in high-definition vector format, which can be viewed at a glance like other .NET applications when coding.

Quick reference manual HD version download: https://beanhsiang.github.io/mlnet.svg


微软技术栈
423 声望997 粉丝

微软技术生态官方平台。予力众生,成就不凡!微软致力于用技术改变世界,助力企业实现数字化转型。